I managed to lock myself out of the root account of an Amazon EC2 Ubuntu instance by changing some permissions to .ssh.
Below are the steps I tried and failed miserable.
- Create a new, temporary instance (created a volume by itself).
- Stop the old instance. At this step, I am able to login to new instance.
- Detach the EBS volume from the old instance (Volume was /dev/sda1).
- Attach the old volume to new instance on /dev/sdb1.
Actual result: 5. Reboot the new instance and now can't login and permission key error. PS: If I dont reboot the new instance, I am able to login but when I am mounting using mount /dev/sdb1 /mnt and I get an error drive not found.
Expected result: 5. Mount the device in new instance. 6. Edit the sudoers file. 7. Unmount the device. 8. Detach the volume. 9. Attach the volume to old instance on /dev/sda1. 10. Boot old instance. 11. Link the old instance back to the elastic IP address. 12. Start breathing again. 13. Delete the temporary instance.