Home  >  Article  >  Operation and Maintenance  >  What is the command to add a user in linux

What is the command to add a user in linux

王林
王林Original
2020-07-17 10:21:2012154browse

The command to add a user in Linux is: useradd or adduser. Both commands can be used to create a user account and create the user's home directory, with superuser permissions. After the account is successfully created, you can use the passwd command to set the account password.

What is the command to add a user in linux

#To add a user in Linux, you can use the command useradd or adduser. These two commands are used to establish user accounts and create the user's home directory. The usage permissions are super users.

(Recommended tutorial: linux tutorial)

Syntax:

useradd[-d home][-s shell][-c comment][-m [-k template]][-f inactive][-e expire][-p passwd][-r]name

Main parameter introduction:

  • -c: Add remark text, which is saved in the remark column of passwd.

  • -d: Specify the home directory when the user logs in, replacing the system default value /home/d6025a37ea8687b5422f951f7288bdc5

  • ##-D : Change the default value.

  • -e: Specify the expiration date of the account. The date format is MM/DD/YY, for example, 06/30/12. The default means it is permanently valid.

  • -f: Specify the number of days after the password expires to close the account. If it is 0, the account will be deactivated immediately; if it is -1, the account will always be available. The default value is -1.

  • #-g: Specifies the group to which the user belongs. The value can be a group name or a GID. The user group must already exist, and the default value is 100, which is users.

  • -G: Specify additional groups to which the user belongs.

  • -m: Automatically create the user's login directory.

  • -M: Do not automatically create the user's login directory.

  • -n: Cancel the creation of a group named by the user name.

  • -r: Create a system account.

  • -s: Specify the shell used by the user after logging in. The default value is /bin/bash.

  • -u: Specify the user ID number. This value must be unique in the system. 0~499 are reserved for system user accounts by default, so the value must be greater than 499.

Detailed description:

useradd can be used to create a user account. It is the same as the adduser command. After the account is created, use passwd to set the password for the account. The account created using the useradd command is actually saved in the /etc/passwd text file.

Example:

For example, we want to create a new user account testuser1, and set the UID to 544. The home directory is /usr/testuser1, which belongs to the users group.

#useradd -u 544 -d /usr/testuser1  -g users -m  testuser1

-m means that if the home directory does not exist, it will be automatically created.

The above is the detailed content of What is the command to add a user in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn