Sudo: /etc/sudoers is owned by uid 501, should be 0

authorizationpasswordsudo

To run programs as sudo without password, I edited /etc/sudoers with wrong content.

Then I re-edited it with Mac's default text editor(course sudo cannot be used when /etc/sudoers is wrong).

I tried to run sudo agin, and get this error:

sudo: /etc/sudoers is owned by uid 501, should be 0
sudo: no valid sudoers sources found, quitting

What should I do? I cannot remember the root password (maybe I haven't ever set root password before).

Best Answer

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.