How to add a user in Linux using useradd command
To add a new user in Linux, use the useradd command. The basic syntax is useradd <username>. The username is the only information required to add a new user, but there are different options available for this command.
The useradd command creates the account, but the account is locked. To unlock the account and create a password for the user, use the command passwd <username>.
By default, the user’s home directory is created and the files from /etc/skel/ are copied into it.
Some important options for useradd command are listed below.
Option |
Description |
-c <full_name> |
Full Name of the user |
-d <home_dir> |
Home directory of the user |
-g <group> |
Default group for the user specified as a group name or group ID number. The group name or GID must already exist. The default is to create a private user group. If a private user group is not created, the default is the users group. |
-G <groups> |
Comma-separated list of additional group names or GIDs to which the user will be a member. Groups must already exist. |
-m |
Create a home directory for the user if it doesn’t exist. Files from /etc/skel/ are copied into the home directory. |
-n |
Do not create a private user group for the user. By default, a private user group is created for the user. |
-p <password> |
Specify an encrypted password for the user. By default, the account is locked until the passwd command is used to set the user’s password. You may use openssl command to create an encrypted password. |
-s <shell> |
Specify the user login shell for the user. The default shell is /bin/bash. |
Example:
[root@localhost ~]# useradd tintin