I was using Ubuntu 14.04 only recently. And somehow I changed permission to /etc/sudoers
file. So every time I run any command using sudo I get these errors:
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
I was able to login as a user and change permissions back. So now when I run ls -l /etc/sudoers
command I get:
-r--r----- 1 root root 755 жов 14 2016 /etc/sudoers
But I was not able to make root an owner. And I still get the same errors, when I try to user sudo.
I have read a lot of scary things about this problem. So could you help me to resolve this problem? I would be very grateful for advice.
Best Answer
Shortcut:
dpkg-reconfigure: If only something is wrong with the permission of
/etc/sudoers
file, with root access run:dpkg-reconfigure sudo
. something likepkexec dpkg-reconfigure sudo
should do the work.visudo: If
dpkg-reconfigure
does not works for you, then just runpkexec visudo
, thesudoers
file will be opened in an editor, then just save and close the file,visudo
will fix the permission for you.After all, if you changed
sudoers.d
directory permissions too, then run:If files are there, and their permissions are as it should be but you still get this error message, the only possibility that come into my mind is that you have broken other permissions and
sudo
does not have access to/etc/sudoers
. the most possible guess is permissions of/etc/
.So run:
We are done, however if you want a detailed instruction to restore broken or removed
sudoers
file with messed up permissions follow along, we are going to use another way to fix things.Introduction
I messed around my
/etc/sudoers
file to get a similar error as you. I get really close, so I completely delete mine and it's became exactly as yours.What I've did to fix the issue:
My root account was locked, and It didn't have any password, so it was impossible for me to do what I wanted to do. however if your root account is active and has a password, switch to root user with
su -
and skip this part. if not, follow the instructions.Before going further I have to mention that You can always use a live disk to do a
chroot
into your system, there are a lot of instruction about chroot using a live disk, so I'm not going to bother with giving all those instruction again, instead I'm going to assume we don't have any live disk and we are going to use what we already have, to fix this issue. If you are happy withcheroot
go that way, that would do the work too.Getting root access
init=/bin/bash
Now you will be dropped into a bash shell with root access. first remount the file system with write access:
Then unlock the root user and set a password on it:
Now If your
/etc/sudoers
still exists on/etc
, move it somewhere else:Because we are going to tell our package manager that this file is missing, and it's going to replace it for us with a correct one, so it shouldn't be there.
We are almost done, reboot your system. login as your normal user, open a terminal then try
su -
to switch into root user. I wasn't able to do this, so what I've done was using CTRL+ALT+F1, to go intotty1
, then I logged in as root with the new password we just set.Bring sudoers back
We simply should reinstall the
sudo
package, however reinstalling does not bring this file back, we should tell thedpkg
to fix the missing config files too, like this:Remember that it will asks you about installing the
/etc/sudoers
file, by insertingy
say yes.If it did not work for you, do as following as root:
Now there may be some different between permissions, run
dpkg-reconfigure sudo
to fix it. if it did not work, runvisudo
as root user, thesudoers
file will be opened in an editor, then just save and close the file,visudo
will fix the permission for you.If everything goes right, your sudoers file will be back and you will be able to use sudo as you were before.