cat /etc/passwd
1. View all users in Linux
(1) In the terminal. In fact, you only need to view the /etc/passwd file.
(2) Look at the third parameter: more than 500, it is the user built later. Others are system users.
Or use
cat /etc/passwd |cut -f 1 -d :
2. User management commands
useradd
Note: Add users
adduser
Note: Add users
passwd
Note: Set passwords for users
usermod
Note: To modify user commands, you can modify login name, user home directory, etc. through usermod;
pwcov
Note: Synchronize users from /etc/passwd to /etc/shadow
pwck
Note: pwck is to verify whether the content of the user configuration file /etc/passwd and /etc/shadow file is legal or complete;
pwunconv
Note: it is the reverse operation of pwcov, which is created from /etc/shadow and /etc/passwd /etc/passwd , and then delete the /etc/shadow file;
finger
Note: View user information tool
id
Note: View user’s UID, GID and user group to which they belong
chfn
Note: Change user information tool
su
Note: User switching tool
sudo
Note: sudo is through Another user executes the command (execute a command as another user), su is used to switch users, and then complete the corresponding tasks through the switched user, but sudo can directly execute the command later, for example, sudo does not need the root password Only root can execute the corresponding command to execute the execution given by root; but it must be realized by editing /etc/sudoers through visudo; Note
visudo
: visodo is the command to edit /etc/sudoers; you can also use vi to edit directly without this command The effect of /etc/sudoers is the same;
sudoedit
Note: Similar to sudo function;
3. Tools or commands for managing user groups (group);
groupadd
Note: Add user groups;
groupdel
Note: Delete user groups;
groupmod
Note: Modify user group information
groups
Note: Display the user group grpck to which the user belongs
grpconv
Note: Synchronize or create /etc/gshadow through the file content of /etc/group and /etc/gshadow, and create it if /etc/gshadow does not exist; Note: Through /etc/
grpunconv
group and /etc/gshadow file content to synchronize or create /etc/group, and then delete the gshadow file
mysql is not in the sudoers file. This incident will be reported.
1. Switch to the root user
2. Add the write permission of the sudo file, the command is:
chmod u+w /etc/sudoers
3. Edit the sudoers file
vi /etc/sudoers
Find this line root ALL=(ALL) ALL, add it below him用户名 ALL=(ALL) ALL
root ALL=(ALL) ALL
maven ALL=(ALL) ALL
nginx ALL=(ALL) ALL
mysql ALL=(ALL) ALL
Add any one of the following four lines
youuser ALL=(ALL) ALL
%youuser ALL=(ALL) ALL
youuser ALL=(ALL) NOPASSWD: ALL
%youuser ALL=(ALL) NOPASSWD: ALL
The first line: allow the user youuser to execute the sudo command (password required). The
second line: allow users in the user group youuser to execute the sudo command (need to enter the password). The
third line: allow the user youuser to execute the sudo command, and execute Do not enter the password.
The fourth line: Allow users in the user group youuser to execute the sudo command, and do not enter the password when executing.
4. Revoke sudoers file write permission, command:
chmod u-w /etc/sudoers
This way ordinary users can use sudo