4

When I type sudo on terminal, I get:

sudo: unable to stat /etc/sudoers: Permission denied
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

More info:

ls -ld / /etc /etc/sudoers
drwxr-xr-x  24 root root  4096 Dez 21 22:44 /
drw-rw-r-x 162 root root 12288 Jan 18 15:13 /etc
-r--r-----   1 root root   746 Jan 18 14:21 /etc/sudoers

pkexec visudo:

Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
3
  • I don't know if it's significant but your /etc permissions look messed up - the default is drwxr-xr-x AFAIK (executable permission is needed in order to traverse directories). Jan 18 '17 at 18:27
  • @EliahKagan why don't you post an answer - since you've done the heavy lifting ;) Jan 18 '17 at 18:43
  • ... aaand upvoted Jan 18 '17 at 19:41
4

Run pkexec chmod 755 /etc to fix this.

As steeldriver suggested, this error is because /etc has the wrong permissions. The permissions shown from ls -ld /etc should look like:

drwxr-xr-x

But yours look like:

drw-rw-r-x

This is preventing sudo from traversing /etc to access /etc/sudoers.

The "permission denied" error message just trying to retrieve metadata on (i.e., to stat) a file nearly always means the file is missing or directories leading to it cannot be traversed, and when you ran ls on the file, it was shown to exist.

I have tested this (on a virtual machine) by breaking permissions on /etc with chmod ug-x, and was able to produce your exact error message. (You shouldn't run chmod with ug-x on it -- that's how I deliberately broke the permissions, not how to fix them.)

To fix the permissions on /etc, give the user and group owners executable permissions. The absence of those permissions is the cause of this problem. In addition, by default /etc doesn't need the group owner to be given write permissions, so unless you know you want this, I recommend changing that back too.

This command will reset /etc to the default permissions:

pkexec chmod 755 /etc

That should work for you since you were able to run other commands as root with pkexec. Other users who find this by searching will usually be able to fix it the same way, but for systems without pkexec (or where pkexec will not work) it may be necessary to boot into recovery mode or from a live CD/DVD/USB to fix the permissions. You shouldn't need to do that, though. Just run that one simple command, and sudo should work again.

0
0

May be this helps, as this method worked for me

If you are not able to open your file through,

sudo vi /etc/sudoers

At first, you should provide permissions as given above by [Eliah][1] and also,

pkexec chmod 755 /etc

Then, try to open the sudoers file using

pkexec vi /etc/sudoers

Edit your changes then save and exit. Try the sudo command now,

sudo apt update 

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.