1. Adding new users
Because the user rights of root are too large in daily use, a user is added for daily use or for other people's use.
- 1 Additional Users
adduser [username]
[root@centos ~]# adduser dex
- 2 Setting Password
passwd [username]
[root@centos ~]# passwd dex Changing password for user dex. New password: Retype new password: sswd: all authentication tokens updated successfully.
- 3 Authorization
The newly created user cannot use the sudo command and needs to be authorized.
Individual users can only have full rights under their own home. Other directories are authorized by others. The permissions of root users are often required, and sudo can be manipulated as root. I remember that I once created a file by sudo and found that I didn't have read and write permissions because the view permissions were created by root.
The newly created user cannot use the sudo command and needs to be authorized.
The authorization management of sudo commands is in the sudoers file. Take a look at sudoers:
[root@centos ~]# sudoers bash: sudoers: No command found... [root@centos ~]# whereis sudoers sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
Find the file location and then view the permissions:
[root@centos ~]# ls -l /etc/sudoers -r--r----- 1 root root 4251 9 25/15:08 /etc/sudoers
Yes, only read-only permissions, if you want to modify, you need to add w permissions first:
chmod -v u+w /etc/sudoers
#Add sudoers file writable permissions
[root@centos ~]# chmod -v u+w /etc/sudoers mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
Then you can add content and add new users under the following line:
[root@centos ~]# vim /etc/sudoers ## Allow root to run any commands anywher root ALL=(ALL) ALL linuxidc ALL=(ALL) ALL #This is a new user.
wq saves and exits. At this time, remember to withdraw write permissions:
chmod -v u-w /etc/sudoers
# Recovering Write Permission
[root@centos ~]# chmod -v u-w /etc/sudoers mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
At this time, use new user login, sudo:
[root@centos ~]$ sudo cat /etc/passwd [sudo] password for linuxidc: We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
The first time you use it, you will be reminded that you are superhuman and responsible. And you need to enter your password to take the next step. If you don't want to enter a password, change the last ALL to NOPASSWD: ALL.
2. Increasing User Groups
- 1 New test Working Group
[root@centos ~]# groupadd testgroup
- 2 Create new dex users and add them to the testgroup Working Group
[root@centos ~]# useradd -g testgroup testuser
Note: - g subgroup - d home directory - s SHELL
- 3 Adding working groups to existing users
usermod -G groupname username
[root@centos ~]# usermod -G testgroup dex
3. Delete Users
- 1 Temporary closure
Close user accounts:
[root@centos ~]$ passwd dex –l
Release:
[root@centos ~]$ passwd dex –u
- 2 Permanent deletion of user account
[root@centos ~]$ userdel dex groupdel testgroup usermod –G testgroup testuser //(Force deletion of all files and subdirectories in the user's home directory and home directory)
- 3 Delete user groups
[root@centos ~]$ groupdel testgroup # Or (force deletion of all files and subdirectories in the user's home directory and home directory) [root@centos ~]$ usermod –G testgroup dex