Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Why this post got downvotes? –  Avinash Raj Mar 23 at 16:47
    
Good question though... –  MrVaykadji Mar 23 at 16:50
1  
Any idea what (applications!, or something else like a malware!) deleted the file? Please edit your question to include that too. This would not only help us understand your problem better, but also help us all linuxers stay safe from such accidents.. big accident actually.. (it's just a guess but there could be some of those rare linux malware! (and a real dangerous one) in your system, have you been experiencing other similar problems lately? please share..) –  precise Mar 23 at 18:19

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer
    
askubuntu.com/questions/73864/… may enrich this answer. –  Minimus Heximus Mar 23 at 16:12
1  
You don't need to use sudo when you try Ubuntu from a live disk. –  Radu Rădeanu Mar 24 at 9:44

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.

share|improve this answer

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

share|improve this answer
    
How would i place this file on /etc? It needs sudo. –  Avinash Raj Mar 23 at 17:09
    
With the root account, the real one, not your usual user with sudo privileges. It's accessible through Recovery I think. –  MrVaykadji Mar 23 at 17:12
    
@AvinashRaj you are right, that would need sudo. So what you'd have to do is boot to a live linux session, and create the file (of course with root privilege) and place the contents (suggested in MrVaykadji's answer) in the file, save it, close the editor, set the right permissions, and reboot.. this should fix a part of the problem (which I think is of a larger domain).. –  precise Mar 23 at 18:40
    
@AvinashRaj You can place files in /etc and change permissions using... guess what?...pkexec. –  Radu Rădeanu Mar 24 at 9:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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