-
Create a new keypair in AWS Console
-
Start a new temporary recovery EC2 instance
-
Stop the lost keypair instance
-
Detach the EBS drive from the lost keypair instance
-
Attach the EBS drive to the recovery EC2 instance (/dev/sdf)
-
Now SSH into the recovery instance and check the attached EBS drives
lsblk -f
-
Make a new temp directory to mount the attached drive
sudo mkdir /mnt/tempvol
-
Mount the drive to the new temp directory
sudo mount /dev/xvdf1 /mnt/tempvol
-
Copy the authorized_keys file to the location on the mounted drive:
cp .ssh/authorized_keys /mnt/tempvol/home/ubuntu/.ssh
-
Unmount the attached drive:
sudo umount /mnt/tempvol
-
Back in AWS Console, detach the drive from the recovery EC2 instance
-
Re-Attach to lost keypair instance as /dev/sda1 (so that its a root drive)
-
Start the lost keypair instance
-
SSH into the lost keypair instance using your new keypair .pem file
-
Breath easy!
Last active
February 19, 2020 03:09
-
-
Save jensendarren/5aa04b463ea8f780ddbe2a095787214c to your computer and use it in GitHub Desktop.
Add new SSH Keypair to an EC2 instance when you have lost your .pem file!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment