User Management in RHEL - useradd and userdel
In Linux, every user has a username, a numeric user ID and belongs to at least one group for use with discretionary access control. Discretionary access control meaning access is granted based on who the user is and what group or groups they belong to.
3 main types of user accounts - superuser [ Privileged user], system users and regular users [non-privileged users]
The name of superuser is root and it has UID 0 and GID 0*.*
System Users do not interactively login using system user accounts.
- UID 1-200 is a range of "system users" assigned statically to system processes by OS.UID 201-999 is a range of "system users" used by system processes that do not own files in the filesystem.
UID 1000+ is the range of "regular users".
User account information is stored in /etc/passwd
User passwords and account aging are stored in /etc/shadow
User account defaults for commands and the shadow utilities are stored in /etc/login.defs
- This login.defs file contains settings for the password aging, minimum and maximum numbers for user IDs, minimum and maximum numbers for system user IDs, minimum and maximum numbers for user group IDs and minimum and maximum numbers for system group IDs.
The process of creating users in Linux is fairly straightforward.
To create a user with username ved, type the below command.
# useradd ved
We do not have to specify any of the options to create a user.
As any option we leave out are taken from the system defaults.
To confirm that the user has ben created, we can check /etc/passwd file
# cat /etc/passwd
or
# grep ved /etc/passwd
The /etc/passwd file shows the various regular user along with the various system users and their respective details in the below format.
ved:x:1001:1001::/home/ved:/bin/bash
The first column "ved" is username
The second column "x" is encrypted password which is stored in /etc/shadow
The third column is a user's numeric ID (UID) number which is unique and is assigned to each user by the OS.
The fourth column is a primary group ID number (GID).
The fifth column is the GECOS field which is used to store general records.
The sixth column is a user's home directory where they'll store their files.
The seventh and last column is the shell to execute upon login.
Deletion of a user
Delete the user but keep their home directory and files
# userdel ved
Delete the user as well as delete their home directory and files
# userdel -r ved
We can view the /etc/passwd file to verify that the account is deleted.
Subscribe to my newsletter
Read articles from Ajit Pandey directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by