Can't fix sudoers permission on osx mojave [duplicate]
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.
You can fix this via AppleScript, without needing to reboot, or even log out & back in, or an existing root shell, or... All you need is a valid administrator password.
Run this command:
osascript -e 'do shell script "chown root:wheel /etc/sudoers; chmod 440 /etc/sudoers; chmod -N /etc/sudoers" with administrator privileges'
...and then authenticate as an administrator when requested.
Explanation: this is a bit indirect. It uses the shell command osascript
to run a short AppleScript that uses the do shell script
command to run a short shell script. The reason for the shell->AppleScript->shell thing is to use the with administrator privileges
option, which has much the same effect as sudo
but will work even if /etc/sudoers is completely messed up.