0

I accidentally messed up my sudoers file earlier and started getting the following error:

>>> /etc/sudoers: syntax error near line 1 <<<
sudo: parse error in /etc/sudoers near line 1
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

I tried to do what this post told me to: https://astrails.com/blog/2009/09/29/how-to-fix-a-hosed-etc-sudoers-file-on-mac-osx

I ran vim /etc/sudoers, and saw a blank file with only two curly brackets there, like so:

{ } ~ ~ ~ ~

I tried to comment out the curly braces, saved the file (despite "read-only" warnings), exited, and ran sudo visudo, which gave me this error:

john is not in the sudoers file. This incident will be reported.

It seems I've been locked out of sudo. Is there any way this can still be fixed? I'm on a 2017 mac running Mojave 10.14.4. I know I shouldn't have messed with the file but just got curious...

5
  • 1
    "I saved the file (despite "read-only" warnings), exited, and ran sudo visudo...", If you can save the file, then why don't you edit and save it?
    – muru
    Oct 15, 2019 at 1:49
  • I'm just worried that I'll mess anything up even more -- I don't know what the original sudoers file should look like / contain. It seems my user got removed from the sudo users, and I'm not sure how to add myself back. The method I used to edit after encountering the syntax error is from the post I linked above: I vim'd into my sudoers file by going into the finder and setting the administrators group on the file to "Read and write".
    – John
    Oct 15, 2019 at 1:51
  • For clarification, this is what I'm doing, and that's the content of my sudo file currently: imgur.com/a/16r5YYI
    – John
    Oct 15, 2019 at 1:56
  • superuser.com/a/424173/334516
    – muru
    Oct 15, 2019 at 2:04
  • Should I copy that file into my sudoers file using vim?
    – John
    Oct 15, 2019 at 2:07

1 Answer 1

0

I figured it out:

I did copy the clean sudoers file to my corrupted one, as @muru recommended, and it worked. I used the following file (I was told it was shipped in the original OSX): paste.md-5.net/fipapovuye.shell I was able to navigate to the file in my finder --> click "get info" (file properties) --> add a user to the permissions tab on the bottom and give the user read+write perms. I then used vim to copy-paste the content, and saved the file.

You must log in to answer this question.

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