Recovery from lost EC2 PEM file: Difference between revisions
(Created page with "Step 1: Before Starting, we must have to note down the original instance availability zone (us-east-1a), Instance name and id you can find this on EC2 dashboard after selecting your instance. Step 2: Launch a new instance with same availability zone (AZ) as we note down before you can select Availability Zone (AZ) at 3rd step (Configure Instance) while creating an instance. Step 3 : At last while we are launching instance we will see the key-pair section (at la...") |
|||
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
=Introduction= | |||
This 10-step process will enable access to an EC2 instance you have lost access to. | |||
This assumes basic AWS / Linux knowledge. | |||
==Take notes== | |||
Note down the AZ of the problem server, its instance name, and the ID of the root volume. | |||
==Make a recovery instance== | |||
Create a new instance in the same AZ | |||
Create a new key pair for the instance and download it. | |||
Don't lose the.PEM file again!!! | |||
==Make recovery instance accessable== | |||
Give the recovery instance an external IP and assign security groups. | |||
==Stop the old instance== | |||
Stop the old instance. | |||
Don't delete it! | |||
==Detatch the root vloume== | |||
Detach the root volume from the old instance | |||
Attach it to the recovery instance - it is best to use /xvdf | |||
==Mount the root volume== | |||
use lsblk to find the root volume, it shoud be /dev/xvdf1 | |||
==Make the Magic happen== | |||
Copy the certs: | |||
sudo mkdir /mnt/removery_vol | |||
sudo mount /dev/xvdf1 /mnt/recovery_vol | |||
cp .ssh/authorized_keys /mnt/recovery_vol/home/ubuntu/.ssh/authorized_keys | |||
==Move the volume back== | |||
Stop the recovery instance | |||
Detach the volume from the old server | |||
Attach the volume back on the old server | |||
==Start the old server== | |||
Sart the original instance | |||
Connect with the new .PEM file | |||
==Cleanup== | |||
Terminate the recovery instance | |||
Latest revision as of 21:07, 8 November 2024
Introduction
This 10-step process will enable access to an EC2 instance you have lost access to.
This assumes basic AWS / Linux knowledge.
Take notes
Note down the AZ of the problem server, its instance name, and the ID of the root volume.
Make a recovery instance
Create a new instance in the same AZ Create a new key pair for the instance and download it. Don't lose the.PEM file again!!!
Make recovery instance accessable
Give the recovery instance an external IP and assign security groups.
Stop the old instance
Stop the old instance. Don't delete it!
Detatch the root vloume
Detach the root volume from the old instance Attach it to the recovery instance - it is best to use /xvdf
Mount the root volume
use lsblk to find the root volume, it shoud be /dev/xvdf1
Make the Magic happen
Copy the certs:
sudo mkdir /mnt/removery_vol sudo mount /dev/xvdf1 /mnt/recovery_vol cp .ssh/authorized_keys /mnt/recovery_vol/home/ubuntu/.ssh/authorized_keys
Move the volume back
Stop the recovery instance Detach the volume from the old server Attach the volume back on the old server
Start the old server
Sart the original instance Connect with the new .PEM file
Cleanup
Terminate the recovery instance