Amazon AWS EC2 Deleted Key Locked out of Root

给你一囗甜甜゛ 提交于 2019-12-08 02:56:17

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/33160673/amazon-aws-ec2-deleted-key-locked-out-of-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!