I. Problem solving
The sudo command is executed with the following prompt:
xx is not in the sudoers file. This incident will be reported.
Cause analysis:This is usually the case when a new user is created without corresponding changes to the sudoers file or the group file.
Solution:
Method 1:
If there is another user besides the root user, you can switch to the other user, then switch to the root user and modify the sudoers file.
Execute the visudo command with no space between vi and sudo. Or vi /etc/sudoers command to add users.
Method 2:
Use su - command (there is a space, use "su" command just switch to root, but not pass the environment variables of root, actually it is the environment variables of the current user, use "su -" command will pass the environment variables, and the same effect as root login), and then modify the sudoers file can be (visudo). If the following situation occurs, don't panic, just enter recovery mode first, and then modify the sudoers file.
ubuntugo intorecovery modeplease refer to: recovery mode
Notes:
username ALL=(ALL:ALL) ALL #User needs to enter password to execute sudo command
%groupname ALL=(ALL) AL # Users in the user group enter their passwords to execute the sudo command
username ALL=(ALL) NOPASSWD: ALL #User executes sudo commands confidentially
%groupname ALL=(ALL) NOPASSWD: ALL #Users in usergroup andy executing sudo commands confidentially
Remarks: (user switch from link)ubuntu root user switch to normal user_Mar.March's Blog-CSDN Blog_root switch to normal user)
1. Ordinary user switches to root user
1, press on su, and then follow the prompts to enter the appropriate root password, you can log into the root privileges.
2, press on sudo su, and then follow the prompts to enter the appropriate root password, you can log in to the root privileges (this command, generally do not need to enter the appropriate root password).
3, press on su root, and then follow the prompts to enter the appropriate root password, you can log in to the root privileges
2. root user cut back to normal user
1, just execute the command: su user (user is your own installation when the user name).
2. Enter exit directly.
3、Ctrl+D key combination exit
How to set a password for the root user:
Just execute the command: sudo passwd root then follow the prompts step by step.