In the previous blog we introduced the user management of the relevant configuration files, including user information file/etc/passwd, user password file/etc/shadow, and then introduced the user group information file/etc/group, user group password file/etc/gshadow. User's home directory, and the user's template directory, then how do we create users? In this blog we will learn about user-managed commands.
1. Add user command: Useradd
①, command name: Useradd
② and English original meaning:
③, command path:/usr/sbin/useradd
④, execute permissions:root
⑤, Function Description: Add new user
⑥, Syntax: useradd "Options" "User name"
-U UID: Manually specifying the UID of the user
-D Home Directory: Manually specify the user's home directory
-C User Description: Manually specify user instructions
-G Group Name: Manually specify the user's initial group
-G group Name: Manually specify additional groups for users
-S Shell: Manually Specify the user's login shell, default is/bin/bash
Note: Add the UID of the option, home directory and so on before the configuration file we have already explained, actually creates the new user does not have to add any option, the default is good.
Example: Add user Tom:useradd Tom.
After you create a new user, the content is automatically generated in the following file:
/ETC/PASSWD: Generating User information
/etc/shadow: Generate password information
/etc/group: Generating user group information
/etc/gshadow: Generate user group password information
/home/tom: Creating a home Directory
/var/spool/mail/tom: Create user mailbox Directory
A number of default values appear, and the user defaults file is as follows:
2, modify the user password: passwd
①, command name: passwd
② and English original meaning:
③, command path:/USR/BIN/PASSWD
④, execute permissions:root
⑤, Function Description: Modify the user's password
⑥, Syntax: passwd "Options" "User name"
-S query the password status of the user password, only the root user is available
-L temporarily locks the user. Only the root user is available
-U unlocks the user. Only the root user is available
-stdin can be used as the user's password with the data output by the pipe character
Note: The root user can modify any user's password, with the syntax of the passwd user name. And ordinary users can only modify their own password, the syntax for passwd, the following can not add ordinary user name, and password to comply with password rules, or can not be modified.
3. Modify user information: Usermod
4, modify the user password status: chage
5. Delete User command: Userdel
Syntax: Userdel "-r" user name
-R Delete User's home directory while deleting user
Executing the above command will automatically delete the following file:
①, deleting user information for/etc/passwd files
②, deleting user password information for/etc/shadow files
③, deleting user group information for/etc/group files
④, deleting the user group password information for the/etc/gshadow file
⑤, deleting a user's mail message rm-rf/var/spool/mail/user name
⑥, delete user's home directory rm-rf/home/user name
Note: Basically the complete removal of a user is to be added to the-r option. How to determine whether the complete deletion of a user, only need to add the user from the new one, if reported as follows error is not removed clean:
6. View User ID
7. Switch user identity Su
Note: Options-never omit, must be switched together with the user's environment variables. Switching from a normal user to the root user is required to enter a password, while switching from the root user to the normal user does not require a password.
8. Add User group: Groupadd
Syntax: Groupadd "Options" group name
-G GID Specify group ID
9. Modify User group: Groupmod
Syntax: Groupmod "Options" group name
-G GID Modify Group ID
-N New Group name modify group name
Example: Change the group name group1 to Group2
Groupmod-n group2 group1
10. Delete User group: Groupdel
Syntax: Groupdel Group name
11. Summary
This blog explains the commands for managing users and user groups, including new, modified, viewed, and so on. Also explained the switch User's command su, this command later used more. Then through this blog and a previous blog, user and user group management is over, the next blog we will enter the introduction of Rights management.
Linux Series Tutorials (15)--linux User management commands for user and user groups