1

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

  • I assume you use bash as your shell. Try EDITOR=nano visudo as root. – Max Ried May 9 '14 at 9:42
  • That worked!!! Thanks very much. I had to make sure I saved it out as sudoers rather than sudoers.tmp – daktau May 9 '14 at 10:46
  • I'll answer it, so you can mark the question as answered. – Max Ried May 9 '14 at 10:58
  • 1
    EDITOR=vi if you're masochistic. – Max Ried May 9 '14 at 16:07
4

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.

0

I ran into this issue today, and was helped along by the information above, but I wanted to keep my editor set to sublime for other purposes. I added the following to my ~/.bash_profile, which solves the visudo issue, but doesn't change my default editor for git, etc.

alias visudo='EDITOR=vi sudo visudo'

When executed, this changes the editor to vi for the command that follows, and lets you edit the sudoers file successfully.

  • You can set SUDO_EDITOR instead of EDITOR to avoid that. Also EDITOR=vi sudo visudo (without a ; before the sudo) changes the value of the env variable only for that command, not for the whole shell. – nohillside Apr 16 '15 at 19:44
  • Thanks @Patrix, good tip re: simplifying my alias, I edited my answer above to reflect that. As for your other tip, I tried adding export SUDO_EDITOR='/usr/bin/vi' to my ~/.bash_profile, but it didn't seem to effect the sudo visudo command at all, my EDITOR environment variable still seemed to be in effect, at least on my machine running OSX 10.9.5. – Dan McCarthy Apr 18 '15 at 14:51
  • You are right. SUDO_EDITOR only works for sudo -e /path/to/file, not for visudo. And sudo -e must not be used to edit the sudoers file because no syntax checking will be done in that case. – nohillside Apr 18 '15 at 14:56
  • Neither EDITOR, nor SUDO_EDITOR work properly for me. I use alias visudo='VISUAL=vim sudo visudo' instead. – Midwire Jul 11 '16 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .