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 am getting sudo errors, how do I fix this error?

sudo: /etc/sudoers is mode 0777, should be 0440
sudo: no valid sudoers sources found, quitting 
share|improve this question
    
As users before have noted, using "chmod 0440 /etc/sudoers" when the sudoers.d/README file has the wrong chmod DOES NOT WORK. –  user2532531 Jul 15 '12 at 9:25
    
Are you suggesting that when the problem is the permissions on /etc/sudoers.d/README, that the error can still say sudo: /etc/sudoers is mode 0777, should be 0440? –  Eliah Kagan Aug 23 '12 at 14:14

6 Answers 6

First Option

Following this post:

  1. Reboot PC
  2. When the GRUB boot selection screen shows, choose Recovery Mode. (If it doesn't come up, press the Shift key when you see the GRUB loader down the bottom).
  3. A black terminal should come up, at this point you can run this command (you should have root privileges):

    chmod 0440 /etc/sudoers
    

Alternatively

You will have to put Ubuntu onto a LiveCD, boot into the LiveCD, mount your Ubuntu Partition on the Hard Drive (Open a file browser, like Nautilus, and click your Ubuntu Partition; or click Places->"xxGB Partition/Your Ubuntu Partition").

Then, open a terminal within the LiveCD session and type these two commands:

cd /media/<name of permanent ubuntu partition>/etc
sudo chmod 0440 sudoers

Extra Problems

If there are any errors (as posted below), follow the error prompt and adjust each file accordingly using one of the above two steps:

sudo apt-get update sudo: /etc/sudoers.d/README is mode 0777, should be 0440 sudo: /var/lib/sudo writable by non-owner (040777), should be mode 0700 [sudo] password for

Fix by following through with:

chmod 0440 /etc/sudoers.d/README
chmod 0700 /var/lib/sudo

Both of these commands should be used appropriately with the outlined steps above. They will change the file permissions associated with that file. 0440 will give the owner (root) and the group read permissions and 0700 will give the owner (root), read, write and execute permissions.

share|improve this answer
    
I can use the sudo command but limited. sudo apt-get update sudo: /etc/sudoers.d/README is mode 0777, should be 0440 sudo: /var/lib/sudo writable by non-owner (040777), should be mode 0700 [sudo] password for –  user20698 Jun 27 '11 at 6:16
    
@Alex: ESC is for GRUB legacy right? Shift should be pressed for GRUB2. –  Lekensteyn Jun 27 '11 at 7:03
    
@user20698: you do not need sudo for the first, the second should be done from a Live CD. –  Lekensteyn Jun 27 '11 at 7:03
    
If sudoers is 0777 shouldn't user be able to run chmod 0440 /etc/sudoers without sudo as sudoers is writable by everybody? –  Seppo Erviälä Jun 27 '11 at 7:46
2  
@Seppo: no, only the owner of a file can change file permissions. –  Lekensteyn Jun 27 '11 at 8:29

sudo is broken in this situation, but pkexec (the command-line frontend to PolicyKit) still works, so you can fix it with a single command. No rebooting is necessary.

pkexec chmod 0440 /etc/sudoers

This assumes PolicyKit is installed. If this is a desktop system (rather than a server with no GUI), it is.

share|improve this answer

Boot into recovery mode, choose the root shell, and:

chmod 0440 /etc/sudoers

Or if you don't want to restart you can use this alternative:

pkexec chmod 0440 /etc/sudoers
pkexec chmod 0440 /etc/sudoers.d/README

it will change the permission. Try it it will work.

share|improve this answer
1  
Why are you chmoding some files to 440 and others to 0440? Shouldn't you use 0440 uniformly? And why are you changing permissions on /etc/sudoers.d/README when you use the pkexec way, but not otherwise? And what about other possible files in /etc/sudoers.d? –  Eliah Kagan Aug 23 '12 at 14:12

What did you do to get these errors?

  • If you did: sudo chmod -R 777 /etc, you need a Live CD to repair this.

    1. Boot into a Live CD and select "Try it"
    2. Mount your Ubuntu partition (or the partition containing /etc if you've put /etc on a separate partition). This can be done by using a file browser like Nautilus or the Places menu
    3. Open a Terminal by going to Applications => Accessories => Terminal
    4. Determine the folder of you Ubuntu partition, you can list the contents of mounted partitions by using ls -l /media. It's possibly named ubuntu or disk. In the next steps, I'll assume ubuntu.
    5. In the Terminal, set restrictive permissions by default:

      sudo find /media/ubuntu/etc -type f -exec chmod g-wx,o-rwx {} \;
      sudo find /media/ubuntu/etc -type d -exec chmod g-w,o-rwx {} \;
      
    6. Next, use the Live CD as reference point for restoring file permissions. The below command will change the file permissions for /etc/media/ubuntu using the /etc folder on the Live CD as reference point. It'll only change permissions on files (-type f) and directories (-type d) on the same filesystem (-xdev). Any errors are written to ~/errors.log Errors like "file not found" indicates that a file on the system is installed, but not found on the Live CD. The command from step 5 should set the right permissions for it, but for the best results, you'd better reinstall the packages.

      cd /media/ubuntu && sudo find etc -xdev \( -type f -o -type d \) -f -exec chmod --reference=/{} {} \; 2>~/errors.log
      
    7. Now safe ~/errors.log somewhere (like http://paste.ubuntu.com/) so you can add it as comment to this answer should you've any problems with applications.
share|improve this answer

In Ubuntu you can first strike Ctrl+Alt+T which opens the terminal. After that you can copy-paste the command below with Ctrl+C and paste in terminal with Ctrl+Shift+V.

pkexec chmod 0440 /etc/sudoers
share|improve this answer

If the PC is start press Ctrl+Alt+F2 and login as root:

machine'sname login : root
password : (empty)

and do:

Following this post:

  1. Reboot PC

  2. When the GRUB boot selection screen shows, choose Recovery Mode. (If it doesn't come up, press the Shift key when you see the GRUB loader down the bottom).

  3. A black terminal should come up, at this point you can run this command (you should have root privileges):

    chmod 0440 /etc/sudoers

share|improve this answer
2  
One does not simply walk into Mordor with the username root! –  Bruno Pereira Feb 4 '12 at 22:02

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.