Linux - User (Uid)

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix

1 - Introduction

Every user who has access to a Linux system needs a login and a password. Each user must belong to a primary group and for security or access purposes can belong to several secondary groups.

In order to create new logins, modify or delete users, you must already be logged in as root.

The root login is the highest level and only certain individuals should have access to the root account.

Red Hat Linux uses the term root in several different ways, which might be confusing to new users. There is:

  • the root account (the superuser, who has permission to do anything),
  • the root account's home directory (/root)
  • and the root directory for the entire file system (/).

When you are speaking to someone and using the term root, be sure to know which root is being discussed.

The easiest way to manage users and groups is through the graphical applications:

  • Red Hat Linux:
    • RHEL4 and higher: system-config-users
    • User Manager: redhat-config-users.
  • SUSE Linux: yast or yast2

The following table lists the available commands line for managing users and groups:

Task Command
Creating groups groupadd
Modifying groups groupmod
Deleting groups groupdel
Creating users useradd
Modifying users usermod
Deleting users userdel
Change/set a password. passwd
Switch to another user su
Verification of the password, group, and associated shadow files pwck, grpck
Conversion to shadow passwords and back to standard passwords pwconv, pwunconv

3 - How to display user and group information

3.1 - User names and primary groups

User names and primary groups are stored in /etc/passwd. This file can be directly edited but this is not recommended.

Format of the file is:

  • User (name normally all lower case)
  • Password (encrypted - only contains the letter 'x')
  • User ID (a unique number of each user)
  • Primary Group ID
  • Comment (Normally the person's full name)
  • Home directory (normally /home/<user name>
  • Default shell (normally /bin/bash)

Each field is separated by a colon.

[root@ebs121 ~]# cat /etc/passwd
gerardnico:x:500:500:Nicolas GERARD:/home/gerardnico:/bin/bash

To see all users who contains the letters “vis” in their names, use the pipe symbol followed by the grep executable which has a pattern as input: '.*vis'

[gerardnico@ebs121 ~]$ cat /etc/passwd | grep -i '.*vis'

3.1.1 - $UID

variable $UID: User ID number

3.1.2 - id

The User Id can seen with:

  • The id command:
uid=0(root) gid=0(root) groups=0(root)
  • or the UID environment variable in Bash.
if [ "${UID}" -eq 0 ]; then
  echo "I'm root"

3.2 - Passwords

Passwords for each user are stored in /etc/shadow. This file should only be changed using the passwd command.

3.3 - Default directories

  • /home — Default location for users' home directories. For example, a user with the username foo has the home directory /home/foo
  • /tmp — The reserved directory for all users to store temporary files. Files stored here are not permanent. A system process removes old files from this directory on a periodic basis. Do not write any files or directories that you want to keep here.

3.4 - Default file - The skeleton directory

The /etc/skel/ directory is for “skeleton” user files, which are used to populate a home directory when a user is first created. This directory can be modified to fit your needs. Modifications only effect new users and does not change anything for existing users.

4 - Management

4.1 - List

cut -d: -f1 /etc/passwd

4.2 - create

4.2.1 - useradd

the useradd command add a new user.


  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)
  • -m (Create the user's home directory)

Example: To add a new user with

  • a primary group of oinstall
  • a second group dba
  • starting shell /bin/bash
  • password of xxxx
  • home directory of gerardnico
  • create home directory
  • a login name of gerardnico
useradd -g oinstall -G dba -s /bin/shell -p xxxx -d /home/gerardnico -m gerardnico

4.2.2 - ansible

user module

- name: "Sqlline - Create the group"
    name: '{{ sqlline_group }}'
    state: present

- name: "Sqlline - Create the user"
    name: '{{ sqlline_owner }}'
    comment: Sqlline Installation user
    shell: /bin/bash
    state: present
    group: '{{ sqlline_group }}'
    password: {{ upassword | password_hash('sha512') }}

4.3 - usermod

This command modify an existing user. You must use all the options in the same way as you create it.


  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)

Example: To add the group 'others' to the user gerardnico

usermod -G others gerardnico

To suppress a group for a user using the command line, you will have to list all the groups that you want the user in. For example if the user currently in group1,group2,group3,group4 and you want him out of group3 then

usermod -G group1,group2,group4 loginName

4.4 - userdel

This command deleta a user,


  • -r (remove home directory)

Example: To remove the user 'gerardnico' and his home directory

[root@ebs121 /]# userdel -r gerardnico
bash: userdel: command not found
[root@ebs121 /]# /usr/sbin/userdel -r gerardnico

4.5 - passwd

This command change/set a password.


  • user's name (Only required if you are root and want to change another user's password)

Example: To change the password for the account you are currently logged in as…

[gerardnico@ebs121 ~]$ passwd
Changing password for user gerardnico.
Changing password for gerardnico
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Example: To change the password for the user 'gerardnico' (only if you are logged in as root)…

[root@ebs121 /]# passwd gerardnico
Changing password for user gerardnico.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

5 - Documentation / Reference