EC2 Instance Recovery: A Step-by-Step Guide
When you need to recover an EC2 instance, especially a Linux instance, EC2 instance recovery becomes crucial. Using key pairs and volume detachment is one of the most effective ways to regain access to your instance. In this guide, we will walk you through the steps involved in securely recovering your EC2 instance.

Step 1: Launch a New EC2 Instance for Recovery
The first step in EC2 instance recovery is to launch a new EC2 instance in the same Availability Zone as the original instance. This ensures compatibility when attaching the old instance’s volume to the recovery instance.
Tip: When launching the new instance, ensure it is in the same AZ to avoid any potential issues with volume attachment. Before launching, create a new key pair to access the recovery instance securely.
Step 2: Detach the Volume from the Original EC2 Instance
To begin the recovery process, stop the original EC2 instance. Right-click on the instance and select Stop from the Instance State menu. Once the instance is stopped, navigate to the Volumes section in the EC2 console.
Find the root volume of the original instance, typically labeled /dev/sda1 under the Attachment Information column. Detach the volume by right-clicking and selecting Detach Volume.
Step 3: Attach the Volume to the Recovery Instance
Once the original volume is detached, it’s time to attach it to the new recovery instance. To do this:
- Right-click on the volume and select Attach Volume.
- Choose the new recovery instance from the dialog box.
- Set the device path to
/dev/xvdf(or/dev/sdf).
With the volume now attached, you’re ready to access it for EC2 instance recovery.
Step 4: Connect to the New Instance
To access the recovery instance, use the key pair you created earlier. First, set the correct permissions for your .pem file:
chmod 600 NewKeyPair.pem
Next, use SSH to connect to the recovery instance:
ssh -i NewKeyPair.pem ubuntu@public_ip
Step 5: Mount the Volume and Update Authorized Keys
Once connected to the new instance, mount the attached volume to access the data. You’ll need to copy the authorized_keys file from the original instance to the new instance. Here’s how:
- Become root:
sudo -i - Create a mount point:
mkdir /mnt/original - Mount the volume:
mount /dev/xvdf /mnt/original - Copy the
authorized_keysfile:cat /home/ubuntu/.ssh/authorized_keys > /mnt/original/home/ubuntu/.ssh/authorized_keys - Unmount the volume:
umount /mnt/original/
This ensures that you can use the new .pem file to access the original instance.
Step 6: Detach and Re-Attach the Volume to the Original Instance
After updating the keys, detach the volume from the recovery instance. Right-click on the volume and select Detach Volume.
Reattach the volume to the original EC2 instance, ensuring it’s attached to the root device path (/dev/sda1).
Conclusion
Following the steps outlined above, you can successfully perform EC2 instance recovery by detaching and reattaching volumes and securely updating the authorized keys. If you need assistance with managing your EC2 instances or other AWS services, ZippyOPS is here to help. We offer consulting, implementation, and managed services, specializing in DevOps, Cloud, AIOps, and more.
For expert guidance, visit our services page or explore our solutions. You can also check out our ZippyOPS product offerings.
To get in touch with our team, email sales@zippyops.com.



