visudo
checks the file syntax before actually overwriting the sudoers
file.
If you use a plain editor, mess up the syntax, and save... sudo
will (probably) stop working, and, since /etc/sudoers
is only modifiable by root
, you're stuck (unless you have another way of gaining root).
Additionally it ensures that the edits will be one atomic operation. This locking is important if you need to ensure nobody else can mess up your carefully considered config changes. For editing other files as root besides /etc/sudoers
there is the sudoedit
command which also guard against such editing conflicts.
sudo
and OS X does have GNU tools. As sudo was first created as an open source application, there's probably no reason for their being many implementations.sudo
andsudoedit
are the same command,sudo
behaves assudo -e
when called assudoedit
. I believe it's just that OS X forgot to add thesudoedit -> sudo
link, but you should still be able to usesudo -e
or callsudo
with argv[0] set tosudoedit
to get the same behavior. – Stéphane Chazelas Jan 23 '13 at 22:41visudo
uses nano by default. – Tim Aug 27 '14 at 17:52ln -s /usr/bin/sudo /usr/local/bin/sudoedit
(actually anywhere in$PATH
) works. – Franklin Yu Jan 15 '18 at 04:49sudo vim /etc/sudoers
and botch the syntax, then I will not be able tosudo vim /etc/sudoers
again to fix it. Effectively, all ability to elevate privileges via sudo will be lost since the system will not be able to parse the file. – Spencer D Feb 10 '18 at 14:43