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:
- Restart your Mac is a single-user mode (press and hold ⌘+S during boot until you see command prompt).
- /sbin/fsck -fy
check the filesystem integrity (not sure it’s necessary, but I did it anyway).
- /sbin/mount -wu /
mount the root filesystem.
- /bin/chmod 1775 /
fix the permissions.
commit the changes to filesystem.
After booting to the normal Mac environment, you may also need to repair permissions with the Disk Utility.