1. View all users
cat /etc/passwd
The first part of each line is the user name.
Regarding uid : 0 means administrator (root), 1-500 means system users, and 501-65535 means ordinary users
cat /etc/group is used to view all user groups, similar to viewing users
Two, add users
groupadd zhangsangroup #Create user group zhangsangroup
useradd -g zhangsan zhangsan Create user zhangsan and join zhangsangroup group
useradd parameters:
- -u UID: Specify UID, this UID must be greater than or equal to 500, and there is no UID occupied by other users
- -g GID/GROUPNAME: Specify the default group, which can be GID or GROUPNAME, and it must also exist
- -G GROUPS: Specify additional groups
- -c COMMENT: specify the user's comment information
- -d PATH: Specify the user's home directory
Three, modify user password
passwd zhangsan
Four, related commands
1. Other user operation commands
- useradd user3 #Add user
- usermod -l u1 user1 #Change the login name of user user1 to u1
- usermod --d /users/us1 user1 #Change the home directory of user user1 to /users/us1
- usermod -g users user1 #Add user user1 to the users group,
- userdel user3 #Delete user
- userdel -r user3 #Delete user and delete home directory
- groupadd users #Add a user group users
- groupmod -n user users #Modify the group name user to users
- groupdel users delete group users
id command to check a user's UID and GID, example: id user4
finger command to view the user's home directory, launch information shell, user name, address, phone, etc. Example: finger user4
Groups command to view the user belongs, for example: groups root
2. The gpasswd command adds users to the group.
Only root and group administrators can change the members of the group:
- gpasswd --a user1 users #Add user1 to the users group
- gpasswd -d user1 users #Exit user1 from the users group
3. Modify file permissions chmod
chmod -R 777 /var/lib/mysql #Indicates that the modified file is the highest authority
-R means to process all files in the specified directory and its subdirectories
4. Modify the user and group chown to which the file belongs
chown -R mysql:mysql /var/lib/mysql
format: chown [option]... [owner][:[group]] file...
-R means to process all files in the specified directory and its subdirectories