Recover from syntax errors in the sudoers file

Feb 15, '07 07:30:02AM

Contributed by: Anonymous

While messing around trying to share my iTunes library between two user accounts on the same iMac, I accidentally introduced a syntax error into my /etc/sudoers file. The big problem here is you need to invoke sudo to edit the sudoers file; I use pico, but visudo is recommended on this site.

So, to recover from this, I had to enable my root account using NetInfo in Applications » Utilities. Log in as root and edit /etc/sudoers, then once it's fixed and working, disable the root account again.

[robg adds: There's a good reason visudo is the recommended way to edit your sudoers file, and this hint is a perfect demonstration of why: because visudo includes a basic check for syntax errors, as explained in the man page:

visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors.
So you really should use visudo if you're going to edit the sudoers file. If you don't, however, and introduce errors, you'll need this hint to fix the problems.]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2007021210565014