The main task of user management is to create a legal user account, set and manage user passwords, modify user account attributes, and delete obsolete user accounts when necessary.
1. Add a new user
In Linux, only the root user can create a new user. The following command creates a user with the login name user1.
# Useradd user1
However, this user is not allowed to log on, because the initial password has not been set for it, and users without a password cannot log on to the system. By default, a user home directory with the same user name will be created in the/home directory. If you need to specify another user's main directory, you can use the following command:
# Useradd-D/home/XF user1
At the same time, the user will get a shell program:/bin/bash upon login. If you do not want the user to log on, you can specify the shell program of the user as follows: /bin/false, so that the user cannot execute commands in Linux even if he logs on:
# Useradd-S/bin/false user1
In Linux, when a user is added, a new group is created. The Group has the same name as the user, and the user is a member of the group. To assign a new user to an existing group, run the following command:
# Useradd-G user user1
In this way, the user is a member of the user group. If you only want to make it belong to another group, you should use:
# Useradd-G user user1
After completing this operation, you should also use the passwd command to set an initial password for it.
2. delete a user
To delete a user, you only need to use a simple command "userdel user name. However, it is best to delete the files that remain on the system. You can use "userdel-r username" to achieve this purpose.
3. Modify user attributes
We have seen how to specify the user's home directory, its shell, and its group when creating a user... And so on. In Linux, a command is provided to implement:
Usermod-G group name-D user main directory-s User Shell
Another direct method is to modify the/etc/passwd file. In this file, each user occupies a line and its content is:
User name: Password: User ID: Group ID: User Full name: User main directory: User Shell
However, it is worth noting that the password is usually replaced by a "*" and you cannot see it.
4. Add a group
Do you still remember that Linux Files can set different access permissions for people in the same group and for people in different groups? You can create user groups as needed:
Groupadd group name
5. delete a group
Similarly, we sometimes need to delete a group. Its command is the groupdel group name.
6. Modify group members
To add a user to a group, you only need to edit the/etc/group file and write the user name to the end of the group name. For example, to add a newuser to a softdevelop group, you only need to find the line softdevelop:
Softdevelop: X: 506: user1, user2
Add newuser to the end to form:
Softdevelop: X: 506: user1, user2, newuser
In addition, in Red Hat Linux, a graphical user management tool, userconf, can be used to manage users more directly.