Fix sudo on a Mac

Sometimes the sudo command stops working for reasons beyond human understanding. When you try to sudo anything, it says: “no valid sudoers sources found”.

It happened to me twice. The first time it happened to a MacBook. I tried to make some changes to the sudoers file, but it didn’t help, and I gave up. After adding an SSD drive to my Mac Pro and moving the system to it, it happened again. Mac Pro is my main working machine, so I had to fix it this time.

Turned out the problem was with the permissions on the root directory. Presumably I’ve somehow broken them while moving my system.

I found a working solution on MacRumors forum. Here’s what you do:

  1. Restart your Mac is a single-user mode (press and hold ⌘+S during boot until you see command prompt).
  2. /sbin/fsck -fy
    check the filesystem integrity (not sure it’s necessary, but I did it anyway).
  3. /sbin/mount -wu /
    mount the root filesystem.
  4. /bin/chmod 1775 /
    fix the permissions.
  5. /bin/sync
    commit the changes to filesystem.
  6. exit

After booting to the normal Mac environment, you may also need to repair permissions with the Disk Utility.

Next