How to access EC2 instance even if pem file is lost

Accessing the EC2 instance even if you loose the pem file is rather easy. 

1. First, create a new instance by creating new access file, call it 'helper' instance with same region and VPC as of the lost pem file instance.

2. Now stop the lost pem file instance. Remember not to terminate instance but to stop it.

3. Goto EBS volumes, select the root volume of the lost pem file instance and detach.

4. Now again select the detached volume and this time you have to attach this volume to helper instance which we created before. Since helper instance already has a root volume by default as /dev/sda1, the newly attached volume will be secondary(eg: /dev/sdf).

5. Login to your helper instance with its pem file.

6. Execute below commands:

# mount /dev/xvdf1 /mnt
# cp /root/.ssh/authorized_keys /mnt/root/.ssh/
# umount /mnt

7. Detach the secondary volume from helper instance. 

8. Again attach the volume back to our recovery instance. Start the instance. Terminate the helper instance.

Use helper instance pem file to log into recovery instance.

    Posted On
  • 17 May 2016
  • By
  • Micropyramid

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Django Hosting on Amazon EC2 with wordpress on same domain

Configuring the Wordpress as subdirectory can be tricky. In this tutorial we will Setup a Django Website alongside a wordpress blog.

Continue Reading...
Using AWS Lambda with S3 and DynamoDB

AWS lambda is handy tool for event driven computation, here we will learn how to configure and setup lambda function so to run our function ...

Continue Reading...
How To Send And Receive Email With Django And Amazon SES

django-ses-gateway a pluggable Django application is used for sending mails from your verified domains and verified emails. We can also use django-ses-gateway for receiving messages ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties