ec2 ssh login failed “permission denied (publickey

2019-05-26 22:31发布

I really messed up this time: I accidentally changed my xxxxx.pem permissions in ~/.ssh/authorized_keys so now I can't login in the SSH anymore ("Permission denied (publickey)"). Obviously I can't either access as root because it is forbidden by default, how can I do to not lost my instance? Changing the permission of the .pem file on my computer won't be useful because the other key to access can't be found (with the right permissions) in ~/.ssh/authorized_keys.

I can't really login in any way, don't know what to do.

Also create an AMI's image to correct the mistake is useless because when I create the AMI from the bad-instance, it replicate the wrong permission of the folder, so I can't login in the new one as well.

Any idea? Thanks

标签: amazon-ec2
1条回答
霸刀☆藐视天下
2楼-- · 2019-05-26 23:19

I messed up an instance once and I was able to recover it by mounting its EBS volume from a separate working instance. Follow these steps:

  • 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 permission issue. Then simply unmount and detach the volume and reattach it to the other instance.

查看更多
登录 后发表回答