Permissions and ownership is a perpetual learning process for beginner Linux administrators. There are quite a few things you need to use superuser privileges for in your everyday administration. But let’s say, for instance, you broke your /etc/sudoers
file (like I did) and now sudo is broken. What do you do then?
Error When Sudo is Broken
If you try to use sudo
when the /etc/sudoers
file is broken, you’ll get an error like this:
sudo: >>> /etc/sudoers: syntax error near line 30 <<<
sudo: parse error in /etc/sudoers near line 30
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
This is not a pretty sight.
And because you can’t use sudo
when the /etc/sudoers
file is broken, that also means that you can’t fix the file with the normal command: sudo nano /etc/sudoers
.
But thankfully, all hope is not lost. There is a relatively easy way to fix this.
What to Do When Sudo is Broken
Since you can’t use sudo nano
, you’ll need to use a different command.
I’m not sure exactly why this works, but if you need to edit the /etc/sudoers
file when sudo is broken, you can open it with this command:
pkexec visudo
You’ll get a response like this:
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: Username,,, (username)
Password:
Enter your password there, and you’ll get this:
==== AUTHENTICATION COMPLETE ===
And then the /etc/sudoers/
file will open for you to edit.
Fix what ever problem you have, save the file, and you’re back in business.
Welcome back to the realm of administrator privileges.
Image credit Nadya Peek.
rene bolders says
Hi New Guy,
I worked in the visudo file to make my password visible (pwfeedback) but somewhere I got a X in the file and it wouldn’t let me get back in there no matter what I tried and ofcourse I lost my sudo privileges! Thanks to your article, I was able to get back in the visudo file and fix my mistake. I would never in a million years find the command: pkexec visudo anywhere !!!! Thanks a million for publishing this insider knowledge, you shure saved me from a lot of grief and timewasting. Once again Thanks ! Rene
PS: I don’t think you are quite a “new” guy in the Linux world 🙂
The New Guy says
Thanks, Rene. I’m glad this helped you out. 🙂