Fix permission denied (publickey) when SSH Access to Amazon EC2
03 May 2019I accidentally messed up the /home/ubuntu/.ssh/authorized_keys
of AWS EC2, and cannot access EC2 from SSH. Here are the steps for fixing it:
-
Detach the bad EBS volume.
-
Create a new EC2 instance, and attach that bad EBS volume to it.
- Mount that bad EBS volume from the new created EC2 instance.
sudo mount /dev/xvdb1 /vol
- Fix the
/home/ubuntu/.ssh/authorized_keys
, and umount and detach the EBS volume.sudo umount /vol
- Attach the fixed EBS volume to root device
/dev/sda1
of the origin EC2 instance.