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.
Full Name of the user
Home directory of the user
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.
Comma-separated list of additional group names or GIDs to which the user will be a member. Groups must already exist.
Create a home directory for the user if it doesn’t exist. Files from /etc/skel/ are copied into the home directory.
Do not create a private user group for the user. By default, a private user group is created for the user.
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.
Specify the user login shell for the user. The default shell is /bin/bash.