1

I just wanted to execute the command ntpdate without typing in a password so I edited the sudoers file via Emacs editor. I simply added one line of code at the end of the file

Boris Boris-MacBook-Air.local = (root) NOPASSWD: /usr/sbin/ntpdate 

I have two Macbooks. One is of 2011 model with EL Capitan OS and sudo version 1.7.10p9. The other is of 2017 model with High Sierra OS and sudo version 1.8.17p1. I did the same thing on both computers. It works on the 2011 Macbook but in case of the 2017 Macbook, after editing, when I call $sudo it prints out an error message.

/etc/sudoers: syntax error near line 63

sudo: parse error in /etc/sudoers near line 63

sudo: no valid sudoers sources found, quitting

sudo: unable to initiate policy plugin

This are lines 60-62

# Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d

I cannot make any sense out of this that why it does not work on the new laptop

  • 1
    What is on line 61,62, 63, and 64 of your sudoers file ? You may replace username with jdoe, jsmith, jane, bob etc if you want ;-) sed -n '61,64p' /etc/sudoers – thecarpy May 4 '18 at 10:47
  • 1
    sudo has come different syntax depending on the version, even in Linux. Unfortunately my Mac is not at hand atm. Please follow the @thecarpy recommendation of not obfuscating so much the real syntax you are using, so we can understand what is happening. – Rui F Ribeiro May 4 '18 at 11:21
  • 1
    @RuiFRibeiro is right, please provide the version of sudo for both systems. sudo -V It is good practice on here to update your question with this information, so everybody can see it without going through all comments... – thecarpy May 4 '18 at 11:51
  • I edited the syntax to the real one I use, sorry about that. The 2011 MacBook has sudo version 1.7.10p9 and the 2017 MacBook has sudo version1.8.17p1. – Boris Sukpholtham May 4 '18 at 22:57
1

Following is the preamble of the sudoers file on my Mac. (I don't believe its wording has changed in the past fifteen years.)

This file MUST be edited with the 'visudo' command as root. Failure to use 'visudo' may result in syntax or file permission errors that prevent sudo from running.

See the sudoers man page for the details on how to write a sudoers file.

Here's a snippet from the visudo man page:

After the edits are made, visudo parses the sudoers file. It will not save the changes if there is a syntax error.

Upon finding an error, visudo will print a message stating the line number(s) where the error occurred and the user will receive a "What now?" prompt. At this point, the user may enter e to re-edit the sudoers file, x to exit without saving the changes, or Q to quit and save changes.

The Q option should be used with extreme care because if visudo believes there is a parse error, so will sudo, and no one will be able to sudo again until the error is fixed. If e is typed to edit the sudoers file after a parse error has been detected, the cursor will be placed on the line where the error occurred.

. . . And that's the reason I actually use visudo instead of, say, nano. If there's a problem, visudo will warn me and direct me to it before I commit and lock not just myself, but everybody out of root access. (Like I did fifteen years ago, not that I'll admit it.) Anyway, since $sudo is complaining about a syntax error on a non-existent line number, I'd bet it's a stray EOF character or similar typocrud causing the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.