Linux useradd Command

Linux 命令大全Linux Command Encyclopedia

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 password. Accounts can be deleted with userdel. 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 <shell>][-u <uid>][用户帐号]

or

useradd -D [-b][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-s <shell>]

Parameter Description:

  • -c<remark> Add a remark text. The remark text will be stored in the remark field of passwd.
  • -d<login directory> Specify the starting directory when the user logs in.
  • -D Change default values.
  • -e<expiry date> Specify the account's expiration date.
  • -f<buffer days> Specify the number of days after the password expires before the account is disabled.
  • -g<group> Specify the group that the user belongs to.
  • -G<group> Specify the additional groups that the user belongs to.
  • -m Create the user's login directory.
  • -M Do not automatically create the user's login directory.
  • -n Cancel creating a group with the same name as the user.
  • -r Create a system account.
  • -s<shell> Specify the shell used by the user after logging in.
  • -u<uid> Specify the user ID.

Examples

Add a general user

# useradd tt

Specify the corresponding user group for the added user

# useradd -g root tt

Create a system user

# useradd -r tt

Specify the home directory for the newly added user

# useradd -d /home/myd tt

Create a user and specify the ID

# useradd caojh -u 544

Linux 命令大全Linux Command Encyclopedia

Other Extensions