CentOS methods for adding and removing users and user groups
- 2020-06-15 11:00:15
- OfStack
1. Account Linux environment mainly in/etc passwd system files, / etc/shadow, / etc/group, and etc/gshadow4 files. 1. The uid of root is 0, starting from 1-499 is the standard account of the system, and ordinary users start from uid 500.
usermod options The user name // Modify existing users
userdel -r The user name // Deleting a user represents their home directory 1 To delete.
groupadd options Group name // Add a new set of
groupmod options Group name // Modify an existing group
groupdel Group name // Delete specific groups that already exist.
Example 2.
Add and remove user commands under CentOS:
Add user test:
adduser test
Change test password:
passwd test
Delete User test:
userdel test
Delete users and user directories:
userdel -r test
Create a new sudo user group
groupadd sudo
Create a new user, test, and join the suso additional group
useradd -G sudo test
Create 1 new user ftpadmin, specify directory as /var/ftp/pub, do not create your own directory (-ES52en)
useradd -d /var/ftp/pub -M ftpadmin
Means to add zh888 to the additional group sudo, which is a new existing user
usermod -G sudo zh888
Means remove directory 1 from zh888 and /home.
userdel -r zhh888
To delete the sudo group
adduser test
0
After the user is created, add a password to the user, and set the imperative passwd passwd option user name
User name Account name // User account password is prohibited
adduser test
1
User name // represents the view of user account password status
adduser test
2
User name // means restore user account
passwd -u
The user name // represents the deletion of the user account password
adduser test
4
4. The chage command is timed to protect the password so that it prevents others from guessing the password.
chage option user name
Parameters have
Example:
The user zhh is required not to change the password within two days, and the maximum password survival is 30 days, and the user is required to notify zhh five days after the password expires
adduser test
5
5. User and group status query commands
Displays the current user name.
whoami
Indicates the group to which the specified user belongs or, if no user is specified, the group to which the current user belongs
groups user name
Switch to another user, if su means switch to your current user.
adduser test
6
Converts the user's current group to the specified additional group, to which the user must belong
adduser test
7
6. Change owner and group
Sometimes you also need to change the owner and the group to which the file belongs. Only the owner of the file has the right to change other owners and groups. Users can transfer their own files to others. Change file ownership using the chown command
chown [-R] < User name or group >< File or directory >
example
Change file files owner to www user
adduser test
9
Change the owner and group of file files to www
chown www.www file
Change the home and group of all files or directories in files to www in all directories and subdirectories
chown -R www.www files/
7. Set the directory of the file and the directory generation mask
Users can use the umask command to set the default build mask for the file. The default build mask tells the system what permissions should not be granted to create a file or directory. If users place the umask command in the environment file.bash_ES174en, they can control access to all newly created files and directories.
umask [a1a2a3] a1 means permission not allowed to belong to a master, a2 means permission not allowed to belong to a group, and a3 means permission not allowed to belong to others.
umask 022// Indicates that the Settings do not allow group users and other users to have write permissions.
umask // Displays the current default build mask.
8. Setting of special permissions
passwd test
3
In addition to general permissions, there are special permissions, 1 some special permissions exist special permissions, if the user does not need special permissions 1 do not open special permissions, to avoid security problems