Linux useradd Command
The Linux useradd command is used to create user accounts.
useradd can be used to create user accounts. After an account is created, use passwd to set its password, and use userdel to delete the account. Accounts created with the useradd command are actually stored in the /etc/passwd text file.
Syntax
useradd [-mMnr][-c <备注>][-d <登入目录>][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-s ][-u ][用户帐号]
or
useradd -D [-b][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-s ]
Parameter Description:
- -c
Add comment text. The comment text is stored in the comment field of passwd. - -d
Specify the starting directory when the user logs in. - -D Change the default values.
- -e
Specify the expiration date of the account. - -f
Specify how many days after the password expires the account will be disabled. - -g
Specify the group to which the user belongs. - -G
Specify the additional groups to which the user belongs. - -m Create the user's login directory.
- -M Do not automatically create the user's login directory.
- -n Do not create a group named after the user.
- -r Create a system account.
- -s
Specify the shell used after the user logs in. - -u
Specify the user ID.
Example
Add a regular user
# useradd tt
Assign an appropriate user group to the added user
# useradd -g root tt
Create a system user
# useradd -r tt
Specify the home directory for a newly added user
# useradd -d /home/myd tt
Create a user with a specified ID
# useradd caojh -u 544
Linux Command Reference