Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon AWS EC2 Deleted Key Locked out of Root

I am running an Ubuntu instance on Amazon AWS EC2. I have a root user named ubuntu. I also have another user named ellis. My ubuntu user is the administrative user that has the control of all other users and creating files and directories in the root.

When I was copying the .ssh/authorized_keys from /home/ubuntu/.ssh/authorized_keys to /home/ellis/.ssh I must have accidentally deleted the directory .ssh that was within ubuntu. Now, I am not able to login to my instance as ubuntu, only as ellis. I tried changing permissions within ellis to gain access to ubuntu with no luck.

I used FileZilla as ellis and was able to see the directories and files within ubuntu, that is why I know that .ssh was removed from ubuntu.

I need to be able to access ubuntu. I have tried copying my ssh directory from ellis to ubuntu, but with the permissions that are set up, nothing administrative can be done from other users. Any way to fix this?

like image 222
David Ellis Avatar asked Jan 07 '23 08:01

David Ellis


1 Answers

You can still access the disk by attaching it to another instance. That way, you can copy across a new key file.

Try this:

  • Stop your instance (let's call it Instance A)
  • Start another Linux instance or use one you already have (let's call this Instance B)
  • Detach your root EBS Volume from Instance A (let's call this Volume A) -- make a note of the mount device, eg /dev/sda1
  • Attach Volume A to Instance B as some /dev/sdf via console. Though device name provided is /dev/sdf, aws might attach it as /dev/xvdf or /dev/xvdf1. You might have to reboot instance B, if you do not see either /dev/sdf or /dev/xvdf or /dev/xvdf1

  • Try to mount the volume /dev/xvdf or /dev/xvdf1, access the content, navigate to the ubuntu user's home directory, store a correct ssh-key

  • Detach Volume A from Instance B
  • Attach Volume A to Instance A (on the same mount-device as above)
  • Start Instance A and try to login
like image 155
John Rotenstein Avatar answered Jan 09 '23 22:01

John Rotenstein