“useradd” Command in Linux
In Linux, a ‘useradd‘ command is a low-level utility that is used for
adding/creating user accounts in Linux and other Unix-like operating
systems.
When we run the ‘useradd‘ command in the Linux terminal, it performs the
following major things:
• It edits /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files
for the newly created user accounts.
• Creates and populates a home directory for the new user.
• Sets permissions and ownerships to the home directory.
How to Add a New User in Linux
To add/create a new user, you’ve to follow the command ‘useradd‘ or
‘adduser‘ with ‘username‘. The ‘username‘ is a user login name, that is
used by a user to login into the system.
Only one user can be added and that username must be unique (different
from other usernames already exists on the system).
For example, to add a new user called ‘tecmint‘, use the following
command.
# useradd tecmint
When we add a new user in Linux with the ‘useradd‘ command it gets
created in a locked state and to unlock that user account, we need to set a
password for that account with the ‘passwd‘ command.
# passwd tecmint
Changing password for user tecmint.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
‘/etc/passwd‘ file
Once a new user is created, its entry is automatically added to the
‘/etc/passwd‘ file. The file is used to store the user’s information and the
entry should be.
tecmint:x:1000:1000:tecmint:/home/tecmint:/bin/bash
The above entry contains a set of seven colon-separated fields, each field
has its own meaning.
• Username: User login name used to login into the system. It should
be between 1 to 32 characters long.
• Password: User password (or x character) stored in /etc/shadow file
in encrypted format.
• User ID (UID): Every user must have a User ID (UID) User
Identification Number. By default, UID 0 is reserved for the root user
and UID’s ranging from 1-99 are reserved for other predefined
accounts. Further UID’s ranging from 100-999 are reserved for
system accounts and groups.
• Group ID (GID): The primary Group ID (GID) Group Identification
Number stored in the /etc/group file.
• User Info: This field is optional and allows you to define extra
information about the user. For example, user full name. This field is
filled by the ‘finger’ command.
• Home Directory: The absolute location of the user’s home directory.
• Shell: The absolute location of a user’s shell i.e. /bin/bash.