If you messed up with editing sudoers, this solution is for you. The solution is limited to restoring /etc/sudoers file to the original state. It is easier to mess up your config such as saving wrong format, etc.
- Please reboot your macOS into recovery mode. While rebooting press and hold
Cmd+Rkey. - After you completely reboot, you will see a dialog. You need to open
Terminalby clickingUtilities > Terminalon menu. - In order to mount
/etcas writable state, you need to disable SIP first by executingcsrutil disable. - Reboot into single user mode. While rebooting press and hold
Cmd+Skey. - Mount
/etcas writable state by executingmount -uw /System/Volumes/Data. - Make sure
/etc/sudoersfile and/etc/sudoers.dfolder ownership is set to root. If not, executechown root:wheel /etc/sudoersandchown root:wheel /etc/sudoers.d. - Make sure there is no
/etc/sudoers~. If yes, please delete it. - Under
/etc/sudoers.ddirectory, delete all files if needed. - Reboot into recovery mode to enable SIP. In terminal execute
csrutil enable. - Finally reboot into normal mode.