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.

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
2  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.