Recover or change lost key pair of AWS EC2 Linux instance
First, note down EBS ID of lost key pair EC2
Then in volume group section search same EBS ID.
Stop the EC2 machine which you want to recover the key.
Detach volume from the volume section
Then attach lost ec2 volume with any working EC2(you must have a key pair of working EC2).
Now login into working EC2 and mount this new EBS volume.
In this example new EBS is “/dev/xvdf2”
[root@ip-10-0-1-98 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 10G 0 disk +-xvda1 202:1 0 1M 0 part +-xvda2 202:2 0 10G 0 part / xvdf 202:80 0 10G 0 disk +-xvdf1 202:81 0 1M 0 part +-xvdf2 202:82 0 10G 0 part
Mount “/dev/xvdf2” to any mount point and replace “authorized_keys” of ec2-user.
[root@ip-10-0-1-98 ~]# mount -o nouuid /dev/xvdf2 /mnt/
Again attach this EBS to the original EC2 instance.
During the attachment take care device name must be “/dev/sda1”
Then start EC2 instance and log in with a new key pair.

