Linux useradd Command
The Linux useradd command is used to create user accounts.
useradd can be used to create user accounts. After the account is created, use passwd to set the account's password. The userdel command can be used to delete the account. The accounts created using the useradd command are actually stored in the /etc/passwd text file.
Syntax
useradd [-mMnr][-c <comment>][-d <login directory>][-e <expiry date>][-f <inactive days>][-g <group>][-G <groups>][-s <shell>][-u <uid>][username]
or
useradd -D [-b][-e <expiry date>][-f <inactive days>][-g <group>][-G <groups>][-s <shell>]
Parameter Description:
-c<comment> Adds comment text. The comment text is stored in the comment field of the passwd file.
-d<login directory> Specifies the user's login directory.
-D Changes default values.
-e<expiry date> Specifies the account's expiry date.
-f<inactive days> Specifies the number of days after the password expires to disable the account.
-g<group> Specifies the user's primary group.
-G<groups> Specifies additional groups for the user.
-m Creates the user's login directory.
-M Does not create the user's login directory.
-n Cancels the creation of a group with the same name as the user.
-r Creates a system account.
-s<shell> Specifies the shell to be used by the user.
-u<uid> Specifies the user ID.
Examples
Add a regular user
# useradd tt
Specify a user group for the added user
# useradd -g root tt
Create a system user
# useradd -r tt
Specify a home directory for the new user
# useradd -d /home/myd tt
Create a user with a specified ID
# useradd caojh -u 544