linux view all users

 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
useraddNote: Add users
adduserNote: Add users
passwdNote: Set passwords for users
usermodNote: To modify user commands, you can modify login name, user home directory, etc. through usermod;
pwcovNote: Synchronize users from /etc/passwd to /etc/shadow
pwckNote: pwck is to verify whether the content of the user configuration file /etc/passwd and /etc/shadow file is legal or complete;
pwunconvNote: 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;
fingerNote: View user information tool
idNote: View user’s UID, GID and user group to which they belong
chfnNote: Change user information tool
suNote: User switching tool
sudoNote: 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;
sudoeditNote: Similar to sudo function;
3. Tools or commands for managing user groups (group);
groupaddNote: Add user groups;
groupdelNote: Delete user groups;
groupmodNote: Modify user group information
groups
Note: Display the user group grpck to which the user belongs
grpconvNote: 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/
grpunconvgroup 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

おすすめ

転載: blog.csdn.net/web15286201346/article/details/126595972