Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 cant 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 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 differnt than normal sudoers file. I just added timestamp_timeout = 0 line in that file and all this problem 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

Hurray !!

share|improve this question
    
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 '09 at 15:25
    
I would look for missing # on comments, missing colons, equal signs, line-continuation backslashes, etc. –  Dennis Williamson Jul 25 '09 at 15:28
add comment

migrated from serverfault.com Jul 30 '09 at 13:41

This question came from our site for professional system and network administrators.

4 Answers

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.

share|improve this answer
add comment

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!
share|improve this answer
    
I was wondering about when it asks for a password before it gives the single user shell ? –  James Jul 25 '09 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 '09 at 16:51
    
Didn't know distros had started doing that, always worked for me in the good old Slackware days –  Andrioid Jul 25 '09 at 17:22
    
You should recommend the use of visudo over vim: en.wikipedia.org/wiki/Visudo –  nagul Sep 11 '09 at 9:15
add comment

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.
share|improve this answer
add comment

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

share|improve this answer
    
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 '09 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.