8zng2g
Last Updated: February 25, 2016
·
543
· meetgodhani
0  owaaqtwvzqpfk3jtmsaab hcn3yffkjkyxlabtzhbzmr bgy4ugxcznjpttuhla1jwror1izxn7

Fixing issue of being locked out in Amazon EC2 Instance (Ubuntu)

When I logged in to my ubuntu instance using ssh and tried to do "su root or sudo su root" it prompted me for password. Actually when you do the setup you don't need to enter password for above command.

If such kind of issue occurs following would be best solution:

  1. Create Temporary instance (Image should be same)
  2. Stop the old instance
  3. Detach Volume disk from old instance.
  4. Attach that volume disk to new temporary instance.
  5. SSH in to your new temporary instance and execute "mkdir /olddisk". 6 Mount your old volume by executing "sudo mount /dev/xvda1 /olddisk".
  6. Go to your "/olddisk" directory you created and edit sudoer (/etc/sudoer) file or just type visudo.
  7. Replace "ubuntu ALL=(ALL) ALL" with "ubuntu ALL=(ALL) NOPASSWD:ALL".
  8. Detach old volume from temporary instance and attached to your old instance as a root. To do that make sure drive is /dev/sda1 which is reserved for root as mentioned here http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html.
  9. Start your old instance.
  10. You can remove your temporary instance and now it won't ask for password when you execute "su root or sudo su root" command.
Say Thanks
Respond