Broken sudo on amazon web services ec2 linux centOS

2

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.

Evan

Posted 2013-10-03T22:32:09.603

Reputation: 123

2If 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 – 2013-10-04T00:28:04.017

Answers

3

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.

David Levesque

Posted 2013-10-03T22:32:09.603

Reputation: 521