While providing sudo
permission to a specific user did a mistake, saved and closed it before I realize. Later when tried to execute sudo -s
encountered the below error message. I’m unable to open sudoers file and edit again to fix it.
ubuntu@digi:$ sudo -s >>> /etc/sudoers: syntax error near line 21 <<< sudo: parse error in /etc/sudoers near line 21 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin
How can I fix this error without booting into single-user mode?
Solution: Fix broken sudoers file
Modern GNU/Linux distribution systems come with a quite fast and easy way to fix the corrupted sudoers file and don’t require rebooting using a live CD, or physical access to the machine.
ubuntu@digi:$ pkexec vim /etc/sudoers ==== AUTHENTICATING FOR org.freedesktop.policykit.exec === Authentication is needed to run `/usr/bin/vim' as the super user Authenticating as: Ubuntu (ubuntu) Password:
It would prompt for the password. Authenticate yourself with the password for the user you are trying to authenticate and then it will open /etc/sudoers
file in your favourite editor (in my case vim
) as root, and you can fix your /etc/sudoers
file.
Unfortunately I get this error message
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
when I’m obviously not doing so.