Services DevOps DevSecOps Cloud Consulting Infrastructure Automation Managed Services AIOps MLOps DataOps Microservices 🔐 Private AINEW Solutions DevOps Transformation CI/CD Automation Platform Engineering Security Automation Zero Trust Security Compliance Automation Cloud Migration Kubernetes Migration Cloud Cost Optimisation AI-Powered Operations Data Platform Modernisation SRE & Observability Legacy Modernisation Managed IT Services 🔐 Private AI DeploymentNEW Products ✨ ZippyOPS AINEW 🛡️ ArmorPlane 🔒 DevSecOpsAsService 🖥️ LabAsService 🤝 Collab 🧪 SandboxAsService 🎬 DemoAsService Bootcamp 🔄 DevOps Bootcamp ☁️ Cloud Engineering 🔒 DevSecOps 🛡️ Cloud Security ⚙️ Infrastructure Automation 📡 SRE & Observability 🤖 AIOps & MLOps 🧠 AI Engineering 🎓 ZOLS — Free Learning Company About Us Projects Careers Get in Touch

EC2 Instance Recovery: A Step-by-Step Guide

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.

EC2 instance recovery using key pair and volume detach

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:

  1. Right-click on the volume and select Attach Volume.
  2. Choose the new recovery instance from the dialog box.
  3. 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:

  1. Become root: sudo -i
  2. Create a mount point: mkdir /mnt/original
  3. Mount the volume: mount /dev/xvdf /mnt/original
  4. Copy the authorized_keys file: cat /home/ubuntu/.ssh/authorized_keys > /mnt/original/home/ubuntu/.ssh/authorized_keys
  5. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top