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...") |
No edit summary |
||
| Line 57: | Line 57: | ||
Congratulations, now you can connect to this instance using newly created instance Private key (.pem) file. | Congratulations, now you can connect to this instance using newly created instance Private key (.pem) file. | ||
Don't lose it again... unless you like doing this! | |||
Revision as of 18:13, 8 November 2024
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 last) from there we have an option for creating and downloading a new key pair and then we can launch the instance. Now we have to login with a newly created instance using new key-pair.
Step 4:
As we know each instance contain one or more EBS volumes, that is instance storage, you have find out EBS volume of lost private-key instance, for that click on Instance Description and find , ‘ Root device ‘ vol-02ee64fe9ba5c7302
Step 5:
Now click on EBS ID this will redirect to EBS Volume page and give a name to this EBS volume so you can identify each volumes. Then we have to detach this volume from the original instance (production instance) for that we have to stop instance (left click on instance select Instance state -> click stop).
Step 6:
Once production instance is stopped, detach EBS volume (left click on volume and select detach) and attach it to the newly created instance. Note: If you didn’t find the newly created instance in Attach Instance wizard than something wrong with your Availability Zone (AZ)
Step 7:
After Attaching EBS to the newly created instance, now you are able to connect this EBS using newly created instance. For that do log in to newly created instance terminal.
Step 8:
After that we have to check whether new EBS is attached successfully or not with new instance you can check by running below command. lsblk – This command is used for determining if the volume is partitioned
Step 9:
If you find another disk than EBS is attached successfully, now we have to replace old authorized_eys (production or lost .pem) with new created authorized_keys for that run below commands.
1. sudo mkdir /mnt/removery_vol 2. sudo mount /dev/xvdf1 /mnt/recovery_vol 3. cp .ssh/authorized_keys /mnt/recovery_vol/home/ubuntu/.ssh/authorized_keys
Step 10:
After successfully changes on authorized_keys, detach this volume from new instance and attach it with Production (lost private-key) instance, after attaching now start production instance.
Step 11:
Congratulations, now you can connect to this instance using newly created instance Private key (.pem) file.
Don't lose it again... unless you like doing this!