MacOS – Using visudo to edit sudoers on Mac

macmacossudoterminal

I have managed to make the sudoers file on my Mac erorr.
eg.

$ sudo visudo
>>> /etc/sudoers: syntax error near line 45 <<<
sudo: parse error in /etc/sudoers near line 45
sudo: no valid sudoers sources found, quitting

So, I went and got the standard sudoers file from here, logged in as root and copied it from Documents to /etc…..but still no joy.

If I try to run 'visudo' using root it fires up Sublime Text and I see a blank sudoers.tmp which I understand is the lock file.

If I try and copy the contents of the downloaded sudoers file into sudoers.tmp using Sublime I get the above error.

So, does anyone have a solution to this?
What should I see when I run the 'visudo' command, Sublime Text and sudoers.tmp?

many thanks,
George

Best Answer

If your visudo does not work as expected, maybe because your editor does not work correctly, try setting the the EDITOR environment variable to a sane value, then launching visudo:

EDITOR=nano visudo

for sh, bash, dash, and compatible.