Original address
When using Ubuntu, we often use the sudo command. However, when using Ubuntu users to log in and use the sudo command, we often need to enter a password. For convenience, we may modify the/etc/sudors file under the root user so that the sudo command does not need to enter a password. At this time, it is inevitable to enter an error, resulting in the sudo command not being used, An error similar to the following appears
>>> /etc/sudoers: syntax error near line 31 <<<
sudo: parse error in /etc/sudoers near line 31
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
Sudo doesn’t work. Under Ubuntu, you usually don’t set the root password, so you can’t enter the root user at all.
At this time, the normal way is to restart the system, enter grub interface, then enter recovery mode, modify sudors file, and restart the system.
But sometimes, the host is not controlled by itself, and only has the permission of SSH login system.
At this time, the following method is the Savior:
Use the following command to edit the sudoers file
pkexec visudo
However, the following errors were reported:
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: ceshi,,, (ceshi)
Password:
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
This incident has been reported.
What should I do?What’s the problem?I don’t know. The correct opening mode is as follows:
1. Open the two SSH terminals and log in with the Ubuntu user
2. Enter the following command at the first terminal to get PID
echo $$
3. At the second terminal, enter:
pkttyagent --process {pid}
Here {PID} is the PID value obtained in the second part (PS: remember to remove {})
4. At this time, the second terminal will be stuck, and input the following at the first terminal:
pkexec visudo
5. Then, the second terminal is also the card owner. When you return to the first terminal, you will be prompted to enter the current user password and enter the
6. OK, after inputting the password, the first terminal card is owned. When you go back to the second terminal, you will find that the content of sudoers appears. If there is any editing error, just save it.
7. Complete the task, modify it, and find that you can continue to use the sudo command, over
PS: the editor used here is nano. Here is a simple way to save nano:
To exit in edit mode under Linux, press Ctrl + X, there are two situations:
① if the file is not modified, exit directlyRead More: