Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I was editing my /etc/sudoers file and saved it but it has a syntax error in there. Now I can't 'sudo vim /etc/sudoers' because sudo thinks the sudoers file is not valid.

How can I fix this?

share|improve this question
See askubuntu.com/a/73872/5078 –  belacqua May 22 '14 at 22:32

4 Answers 4

up vote 4 down vote accepted

Boot the system into single mode and then edit it.

share|improve this answer
Thanks, my Ubuntu is running under Virtualbox. How do I boot into single user mode? –  fred basset Nov 27 '10 at 22:41
I don't get the grub options at boot time however, it boots straight into Ubuntu... –  fred basset Nov 27 '10 at 23:04
Try holding <Ctrl> or something. –  Ignacio Vazquez-Abrams Nov 27 '10 at 23:05
@red basset: As the vm starts press Esc several times that should drop you into grub then select the recovery mode option. –  Iain Nov 27 '10 at 23:13

You should never edit your sudoers file directly. Use visudo - it will protect you from these syntax errors in the future.

To recover from this situation, either boot into single-user mode and edit the file or boot off of a livecd and do the same.

share|improve this answer
Thanks, I was wondering what visudo did differently. I need to work out now how to boot into single user mode. My Ubuntu is running under Virtualbox. –  fred basset Nov 27 '10 at 22:43
visudo causes you to edit a copy of the sudoers file. It will only replace the sudoers file if it validates when you save it. It will use the editor specified by your EDITOR variable, so you can use your prefered editor. It can also be used in check mode if you edited the file and want to be sure it is still valid. –  BillThor Nov 28 '10 at 0:13

As noted in this similar question on askubuntu, this may well work without having to reboot into single-user mode:

pkexec visudo
share|improve this answer
This is the by far the easiest way to do it, if it's available. –  belacqua May 22 '14 at 22:33

By the way, if you have the root password, just login with it and set it back the way it was.

chmod 0440 /etc/sudoers

This will avoid you from booting into single-user mode or worst, booting from a livecd.

In my case I couldn't afford to bring the server down.

share|improve this answer

Your Answer


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

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