6

I get the following error while trying to update my repositories,

avinash@avinash-VirtualBox:~$ sudo apt-get update
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

It seems like I had accidentally deleted my /etc/sudoers file./etc/sudoers file was actually belongs to sudo package, so i try to reinstall sudo by pkexec but it won't work.

avinash@avinash-VirtualBox:~$ pkexec apt-get install sudo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
sudo is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 301 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
Setting up sudo (1.8.6p3-0ubuntu3.1) ...
WARNING:  /etc/sudoers not present!
chown: cannot access ‘/etc/sudoers’: No such file or directory
dpkg: error processing sudo (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 sudo
E: Sub-process /usr/bin/dpkg returned an error code (1)
avinash@avinash-VirtualBox:~$ 

And also I had tried,

avinash@avinash-VirtualBox:~$ pkexec apt-get install --reinstall sudo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 301 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for sudo:amd64

How can i make sudo command to work again?

Avinash Raj
  • 80,446

5 Answers5

8

After I made a backup for /etc/sudoers file:

sudo mv /etc/sudoers{,.bak}

I get the same errors like in your case.

If you use

pkexec apt-get install sudo

will not work because apt-get will see that:

sudo is already the newest version.

If you use:

pkexec apt-get install --reinstall sudo

will also not work because /etc/sudoers file is not found to be removed and replaced.

But if you use:

pkexec apt-get purge sudo
pkexec apt-get install sudo

as described in this answer, everything will work like a charm. I can say this because I just test it again.

So, there is no point to lose time and boot your system with a live disk.

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
5

Just boot from Ubuntu live disk and copy /etc/sudoers file to the installed Ubuntu partition's /etc directory.

  • Boot Ubuntu live dis and click try Ubuntu option on startup.

  • Run sudo blkid command to know the installed Ubuntu's partition id.

  • Mount the installed Ubuntu's partition on a specific directory like below,

    sudo mkdir /media/foo
    sudo mount /dev/sdaX /media/foo     # /dev/sdaX installed Ubuntu's partition id.
    
  • Now copy the live disk's sudoers file to the /etc directory of installed Ubuntu's partition.

    sudo cp /etc/sudoers /media/foo/etc
    
  • Now boot from the hard-disk(Boot your Ubuntu OS).It will work.

Avinash Raj
  • 80,446
4

Here's the raw content of /etc/sudoers on Ubuntu 13.10 :

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# 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

And the permissions :

-r--r----- 1 root root

To apply those, it's chmod 440 /etc/sudoers and chown root:root /etc/sudoers

MrVaykadji
  • 5,965
3

execute pkexec nano /etc/sudoers

and paste

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# 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
1

I just wanted to add this simple solution to reinstall sudo If you removed sudo with:

sudo apt-get remove sudo

You can install it again. Use:

su -

Enter your root password and then:

apt-get update
apt-get install sudo

exit

muru
  • 207,228