User and group management in Linux command line interface
Use of the useradd and passwd commands for user and group management on the Linux command line interface
Useradd [-c comment] [-d dir] [-e expire] [-g group] [-G group1, group2...] [-m [-k skel_dir] [-u uid]
[-S shell] username
Passwd [username]
Bytes --------------------------------------------------------------------------------------------
Description of the useradd command
-C comment: the user's General Information Description. comment is a string, but it cannot contain the colon ":" And cannot contain the character "#!". As the Terminator
-D dir: Specifies the user's home directory. the dir parameter is the complete path name.
-E expire (expiration): indicates the end date of the user account. The expire parameter is a string of 10 characters in MMDDhhmmyy format. MM indicates month, DD indicates day, hh indicates hour, mm indicates minute, and yy indicates year, the last two digits from 1939 to 2038. All characters are numbers. If the expire parameter is 0, the account will never expire. The default value is 0.
-G group: the group to which the user belongs (main group ). The group parameter must contain a valid group name and cannot be empty.
-G group1, group2,... identifies the secondary group to which the user is added
-K skel_dir: copy the default file from skel_dir to your home directory and use it with-m.
-M: If the user's home directory does not exist, one is automatically created. Create a home directory by default
-S shell: Specifies the shell used for logon. The shell parameter is the complete path name. Bash tcsh zsh and so on
-U uid: indicates the uid of a user. Uid is a unique integer. You should avoid modifying this attribute to avoid compromising system security.
Note: during normal use, if there are no special requirements, too many parameters are not required.
Certificate --------------------------------------------------------------------------------------------------------------------------------------
Passwd command explanation
The root user can modify the password of the user corresponding to the username parameter, while the common user can only change his/her password. When only his/her password is modified, the username can be omitted
Certificate --------------------------------------------------------------------------------------------------------------------------------------
The simplest usage is useradd username, which uses the default option
For example, add a user
# Useradd lily
The system automatically performs the following tasks for the user:
* Allocate a new user ID for user lily. The value is 1 for the existing largest user ID in the system.
* Add a row of information in/etc/passwd and/etc/shadow.
* Create a new user home directory for the lily user. The path is/home/lily.
* Create a main group named lily for the user and add a row of information to/etc/group.
* Set the default logon shell to/bin/bash.
* Set the user's account to never expire
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------
The following example shows how to add a user using the useradd command.
For example, create a user name named Jack, the description is Jack, the user group is mary (assuming there already exists), the login shell is/bin/bash, and the home directory is/home/Jack
# Useradd-c "Jack"-g mary-s/bin/bash-d/home/Jack
After creating a user, you can set a password for the user. (Normal users can only change their own passwords)
# Passwd Jack
The following message is displayed:
Changing password for user Jack
New passwor: note that the password is not displayed for security reasons. After the password is entered, press enter to confirm.
Retype new password:
If the two passwords are the same, that is, the password is successfully modified, the following prompt will be displayed:
Passwd: all authentication tokens updated successfully.
If the input is incorrect, that is, the password cannot be modified. Just run the passwd command again.
For more details, please continue to read the highlights on the next page: