Unable to stat /etc/sudoers: no such file or directory

Shortcut:

dpkg-reconfigure: If only something is wrong with the permission of /etc/sudoers file, with root access run: dpkg-reconfigure sudo. something like pkexec dpkg-reconfigure sudo should do the work.

visudo: If dpkg-reconfigure does not works for you, then just run pkexec visudo, the sudoers 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:

pkexec chmod 755 /etc/sudoers.d

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:

pkexec chmod 755 /etc

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 with cheroot go that way, that would do the work too.


Getting root access

  • Reboot your system
  • When grub appears press e to edit it
  • At the end of the line which starts with linux, add init=/bin/bash
  • Press CTRL+X

Now you will be dropped into a bash shell with root access. first remount the file system with write access:

mount -o remount,rw /

Then unlock the root user and set a password on it:

passwd -u root
passwd root

Now If your /etc/sudoers still exists on /etc, move it somewhere else:

mv /etc/sudoers /etc/sudoers.broken

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 into tty1, 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 the dpkg to fix the missing config files too, like this:

apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall sudo

Remember that it will asks you about installing the /etc/sudoers file, by inserting y say yes.

If it did not work for you, do as following as root:

mkdir /root/tmp
cd /root/tmp
apt-get download sudo
dpkg-deb -x sudo*.deb .
cp etc/sudoers /etc/sudoers
cd /root
rm -r tmp

Now there may be some different between permissions, run dpkg-reconfigure sudo to fix it. if it did not work, run visudo as root user, the sudoers 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.