7

I changed settings in sudoers file using

sudo visudo 

and messed it up. Now when I try to do it again or open any file using sudo, I can't open it anymore and I get this error message:

>>> sudoers file: syntax error, line 7 

What now?

Is there any way to get out of this problem (to revert the settings), or do I need to install a fresh copy of linux ?

The reason I got all this is I pressed "Q" while it was telling me there was some error, which was very stupid of me.

Thanks.


EDIT: My sudoers file is no different than normal sudoers file.

I just added timestamp_timeout = 0 line in that file and all these problems arised.

I did what James suggested and even removed that line (timestamp_timeout = 0).

I changed file permission to 0440 which it requested, and then boot normally. Then, I get the same error message:

sudoers file: syntax error, line 7 
sudo: parse error in /etc/sudoers near line 7

as above.

What should I do now ??


EDIT 2 Solved: This is what I did:

  1. Boot using livecd
  2. Remove the old sudoers file
  3. Made new sudoers file and copied everything to that file i.e. minimum configuration settings, which I luckily had saved in another file
  4. Changed file permission to 0440
  5. Reboot again normally from harddrive

Hooray!

2
  • you could paste the contents of your sudoers file to www.pastebin.com and let us take a look, probably the fastest way.
    – Andrioid
    Jul 25, 2009 at 15:25
  • I would look for missing # on comments, missing colons, equal signs, line-continuation backslashes, etc. Jul 25, 2009 at 15:28

5 Answers 5

7

Assuming you didn't give the root user a password then the easiest way to fix this is with a live cd such as Knoppix. Boot of the CD. Mount the local disc, edit the file, unmount the disc and reboot.

5

Simple, boot the computer in 'single user mode' by doing the following steps:

  1. Reboot
  2. When Grub starts, press ESC (or escape)
  3. Press 'e' for editing the current line
  4. Add 'single' to end of the line containing 'linux'
  5. Boot (press b)

This will start the computer with only one user, root. From there follow these steps:

  1. /usr/bin/vim /etc/sudoers (or use nano, might be easier for you) to fix the problem
  2. If you're unsure of the problem, try copying the included example of sudoers from "/usr/share/doc/sudo/examples" (varies) and of course add your user there.
  3. Save the file, exit Vim
  4. Reboot, enjoy!
4
  • I was wondering about when it asks for a password before it gives the single user shell ?
    – James
    Jul 25, 2009 at 16:30
  • This method doesn't work for all distros. Since it's a well-known back door, some distros force a login before you get to a root prompt. It sounds like that is the case for you, James.
    – Telemachus
    Jul 25, 2009 at 16:51
  • Didn't know distros had started doing that, always worked for me in the good old Slackware days
    – Andrioid
    Jul 25, 2009 at 17:22
  • You should recommend the use of visudo over vim: en.wikipedia.org/wiki/Visudo
    – user4358
    Sep 11, 2009 at 9:15
3

James' idea to use a live cd (assuming the root account is not enabled) is a good one. I would add a few points.

  • First, you might get lucky and a backup of the /etc/sudoers file was automatically saved when you were editing it. Check in /etc for a file that looks like this sudoers~ (you can cd to that directory and run ls -A without root privileges, even if you can't read or edit the files as a regular user).Some editors will create such a backup if at all possible, so you may have one without having created it explicitly.
  • Second, if you have no idea how to edit the file, you might consider posting it (or the area around line 7) here or elsewhere. Although the file itself has to do with security, there aren't passwords in it, so there's no immediate harm in posting it.
  • Last, note that an error message like the one you saw doesn't necessarily mean that the problem itself is literally on line 7. The error might be on line 4, but only got tripped off, so to speak, on line 7.
1

For those of us who don't have a console or local access to the server to boot into run level 1 or have root set(or the credentials/certs available), use pkexec visudo or pkexec vi /etc/sudoers, visudo is better as it does error checking on the file.

1
0

Try pressing e, for edit. This should let you edit the file and correct the errors.

1
  • Pressing 'e' when you get shown the error, after you finish editing, will drop you back in so you can fix your errors. Unfortunately it's doesn't explicitly mention this to you.
    – furinkan
    Jul 25, 2009 at 15:06

You must log in to answer this question.