I now know that I should never try to edit the etc/sudoers file with a regular text editor. However, minutes before I learned this, I saved a new user name in the file with Sublime Text. Now when I run sudo cat sudoers for example, I get 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

How can I get out of this quandary?

  • Presumably, your root account doesn't have a password that you know of? In that case you could try su. Otherwise, rebooting single-user or off a live CD should be the second easiest way to revert your file; I'll let someone post a proper answer if su doesn't do the trick. – dhag Apr 13 '15 at 2:52
  • I used su - root and now I get permission denied. I also tried to reboot as single user and edit the file, but got the error that I was in a read-only filesystem. – steel Apr 13 '15 at 3:11
  • 1
    If you booted from CD etc then the root is the root of the CD and readonly. see instructions on mounting your root bellow. If you booted in single user mode using grub, then it may be the correct root, but readonly. If so then you need to remount rw from what I can remember mount -o remount,rw / – ctrl-alt-delor Apr 13 '15 at 11:16

I see you've tagged your question osx so if you've done this on a mac, make use of the GUI.

  1. Open any Finder window and press cmd shift G
  2. Type /etc/sudoers and press return to go to the file
  3. Press cmd i with the file highlighted
  4. Scroll to the bottom of that info window to 'Sharing & Permissions' and click the lock icon in the bottom right
  5. Type an admin username and password
  6. Now add yourself in that window with the + button and select 'Read and Write' privileges
  7. Open the file in any editor and fix what you screwed up the first time!
  • Brilliant. And all through the GUI! Thank you. – steel Apr 16 '15 at 16:11
  • 1
    Adding permission to write to /etc is also required to change the sudoers file. – tsafrir Oct 21 '15 at 19:00
  • I have same problem with my ubuntu. Can you please give some idea to fix in ubuntu ? – Shyamkkhadka May 24 '18 at 5:38

I was unable to edit the sudoers file by adding my username in the "sharing and permissions " and changing the permission to "read and write".

I was unsuccessful in creating a new file and changing its permission to root:wheel and 0440.

Finally I had to go to recovery mode (restart -> cmd+R)

  1. Mount Macintosh HD through disk utility
  2. go to Terminal through utilities
  3. go to cd Macintosh HD/private/etc
  4. edit sudoers file to correct the mistakes.
  5. save and change permissions if needed. sudoers file needs root: wheel. If its not, sudo won't be run. chown root:wheel sudoers
  6. I had also changed the permission to 0440 since initially i removed sudoers and created a fresh copy when i was logged in.

Thanks @toxefa, it is working for me by modify permission by info GUI and edit sudoer file.


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.