Lost your PEM files? Use these steps to connect AWS Instance!
Worried about your PEM files? Here we have listed out a set of strategies you need to follow to get connected with AWS Instance.
This process is applicable if you have lost your .pem or .ppk key.
Initially, you need to take a snapshot of the root volume of your instance.
Secondly, you can create a new instance (for temporary purposes) in the same AZ just as the original instance. And remember, it is highly suggested that the recovery instance should be same as OS.
Once you create a snapshot of the instance, you need to stop the original instance.
You need to detach the root EBS volume from the original instance and make sure you make a note of volume (example /dev/xda or /dev/sda).
Once you are done with detaching, refer to the status column. Ensure the status being changed to availability. Attach this detached volume to the newly created temporary instance.
Make sure you mention your instance name while attaching the volume and device name like /dev/sdf or /dev/xdf.
The next steps are to mount it in /mnt folder since it is a secondary folder.
Commands to list attached block devices:
$ lsblk xvda 202:0 0 8G 0 disk └─xvda1 202:1 0 8G 0 part / xvdf 202:80 0 8G 0 disk └─xvdf1 202:81 0 8G 0 part
Mount the secondary device (dev/xvdf1) to ‘/mnt’ mount point using the command:
# mount /dev/xvdf1 /mnt/
If you need to change the authorized key in original instance, check the .ssh directory.
You need to create a backup of the old authorized key in the original instance.
/mnt/home/ubuntu/.ssh/authorized_keys to /mnt/home/ubuntu/.ssh/authorized_keys_back
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id nisl ac arcu aliquet aliquet. Praesent laoreet rhoncus elit, rutrum feugiat metus tempora.
$ lsblk
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 8G 0 disk
└─xvdf1 202:81 0 8G 0 part