Apple - sudo: /etc/sudoers is owned by uid 501, should be 0

You can boot into single user mode by pressing Cmd-S on startup (see OS X: How to start up in single-user or verbose mode for details) which should give you a root shell. Then run

mount -uw /
chown root:wheel /etc/sudoers
chmod 440 /etc/sudoers
reboot

to fix the problem and restart.


For macOS Mojave, here is what worked for me:

  1. Start up in recovery mode (Cmd+R during boot up)
  2. Disk Utilities > Select Macintosh HD, and Mount
  3. Close Disk Utilities
  4. Utilities > Terminal
  5. Type: chown root:wheel "/Volumes/Macintosh HD/etc/sudoers"
  6. Reboot

You may also need to change the ownership of ts, back in the Terminal:

sudo su
sudo chown -R root:wheel /var/db/sudo/ts/

Yosemite and earlier OSX keeps info on what permissions system files (i.e. files the OS installs) should be. Apple's doc

To restore this use Disk Utility.app.
Select the boot volume (by default called Macintosh HD) on the left hand side.
Click the Verify or Repair Disk Permissions - the latter will reapply the stored permissions.

To edit sudoers in the future I would use visudo which checks that the edit is valid

re the root password you probably have not set it before - the idea of sudo is that you never need to use it and Apple disables root login by default