Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I had no idea of the dangers of messing with the /etc/sudoers file, and was just trying to make a simple change in there. However, I seem to have put something with incorrect syntax in there, causing this problem:

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

I can't edit the /etc/sudoers file anymore because I don't have root access.

One fix I see online is to use:

$ su -

and enter the root password. However, this amazon ec2 box doesn't seem to HAVE a root password, thus preventing me from using su -

The other thing I see is rebooting the computer and doing some single user stuff which allows you to reset the password. Big problem is that this is amazon ec2 and I'm just SSHing into the box, I don't have physical access.

Question, am I completely screwed or is there a possible workaround? This is not Ubuntu, it appears to be CentOS. I also understand now about visudo, but the site I had gotten the change from didn't mention that.

share|improve this question
If you cannot get root access, you will not be able to access the files needed to fix this. You should probably contact Amazon for support. – hololeap Oct 4 '13 at 0:28
up vote 1 down vote accepted

I messed up an instance in the exact same way once and I was able to recover it by mounting its EBS volume from a separate working instance. There are many steps involved:

  • From the EC2 Management Console, stop your EC2 instance
  • Go to the Volumes screen and detach the problematic EBS volume from the instance
  • Fire a new, fresh micro instance using a stock Linux AMI with default options (unless you already have another working instance)
  • Once the new instance is running, attach the problematic EBS volume to it
  • Then mount it

Once mounted as a directory, you should be able to access the filesystem of the problematic volume from the new instance and fix the sudoers file. Then simply unmount and detach the volume and reattach it to the other instance.

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.