4

I have a problem:

I don't have a root password on my mac. I just have an Admin account, which can do stuff using sudo. Now, I wanted to add my normal user to the /etc/sudoers file as well. Since it did not let me write to that file (even writing using sudo), I did this:

sudo chmod u+w /etc/sudoers

That worked. But since then I can't do any sudo command anymore on my system. It complains that /etc/sudoers has the wrong mode:

$ sudo touch /etc/sudoers 
sudo: /etc/sudoers is mode 0740, should be 0440
Segmentation fault

It sounds like a bad joke, because now I can't even change the mode back to 0440:

$ sudo chmod 0440 /etc/sudoers 
sudo: /etc/sudoers is mode 0740, should be 0440
Segmentation fault

Is there any way to fix this situation? I need to get my sudo abilities back.

4
  • 2
    Hm. Sounds like you did the wrong thing. To give a normal user sudo rights, you could add them to the wheel group. You might be able to chmod the file, running in single user mode, after entering mount -uw /. (cough, backup!, cough)
    – slhck
    Jul 21, 2011 at 8:29
  • @slhck You're super old-school. Apple hasn't used the wheel group for that in ages. It's been the admin group for several major Mac OS X versions now. But adding a user to the admin group is all that checking the "admin" checkbox in the Accounts pref pane does anyway.
    – Spiff
    Jul 21, 2011 at 9:43
  • @Spiff. Yeah I always mix that up, my bad. Will do that, thanks!
    – slhck
    Jul 21, 2011 at 9:50
  • @slhck Oops when I realized I could suggest Repair Disk Permissions I decided to write my own Answer and I stole your suggestion. I suck. :-(
    – Spiff
    Jul 21, 2011 at 9:55

2 Answers 2

7

This may be one of the rare cases where running "Repair Disk Permissions" from Disk Utility might actually be warranted.

If that doesn't work, follow @slhck's suggestion of booting into single user mode to fix it:

  1. Reboot, holding down Command-S to enter single user mode. Note that if you're using a Bluetooth keyboard, you need to hit this as the boot chime is trailing off. If you hit it too soon, it's before the Bluetooth radio gets reset and the keyboard loses connection and doesn't communicate the keypress. If you hit it too late, the boot process will have moved on to multi-user boot.

  2. Follow the instructions on-screen to remount your root drive read-write. You can probably skip the fsck step if you rebooted gracefully. So you can probably just type:

    mount -uw /

  3. Fix the permissions on /etc/sudoers. Note that you're already root when you're in single user mode, so you don't need to sudo this.

    chmod 0440 /etc/sudoers

  4. Exit single user mode by rebooting again, by simply typing:

    reboot

0
3

Another approach is using Automator.app

Create a new workflow that contains something like the following:

do shell script "chmod 0440 /etc/sudoers" with administrator privileges

When you run it, it'll ask for your password and (presuming you're an administrator) it'll fix it.

This also works if you've messed up the permissions on a parent directory (eg making / something other than 755).

2
  • Nice and quick solution; saves rebooting into single user mode. Need to learn more apple script; interesting stuff. Dec 10, 2012 at 10:11
  • saved my day - thx
    – froderik
    Jan 14, 2013 at 10:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .