Is it possible to change the pem file after creating an Instance

0 votes
I actually have lost the key file for accessing my EC2 instance can anyone help me as how to get it or change the key file?
Jan 14, 2019 in AWS by Anjali
• 2,950 points
1,213 views

2 answers to this question.

0 votes
answered Jan 14, 2019 by nishant
0 votes

Here are the steps you can follow:- I got it from a blog i read few days back. 

  1. Stop the running EC2 instance
  2. Detach its /dev/xvda1 volume (let's call it volume A) 
  3. Start new t1.micro EC2 instance, using my new key pair. Make sure you create it in the same subnet, otherwise you will have to terminate the instance and create it again.
  4. Attach volume A to the new micro instance, as /dev/xvdf (or /dev/sdf)
  5. SSH to the new micro instance and mount volume A to /mnt/tmp
  6. $ sudo mount /dev/xvdf1 /mnt/tmp
  7. Copy ~/.ssh/authorized_keys to /mnt/tmp/home/ubuntu/.ssh/authorized_keys
  8. Logout
  9. Terminate micro instance
  10. Detach volume A from it
  11. Attach volume A back to the main instance as /dev/xvda
  12. Start the main instance
  13. Login as before, using your new .pem file
answered Jan 14, 2019 by Sukesh

Related Questions In AWS

+2 votes
3 answers

Is it possible to ping AWS EC2 instance

1.Go to EC2 Dashboard and click "Running ...READ MORE

answered Nov 13, 2020 in AWS by shivam
• 140 points

edited Nov 13, 2020 by Gitika 20,377 views
0 votes
1 answer

What is the porcess to add swap to an EC2 Instance?

If you are finding problem with your ...READ MORE

answered Mar 27, 2019 in AWS by Himanshu
499 views
0 votes
1 answer

Using Shapely on AWS Lambda with Python 3

For some reason, the pip install of ...READ MORE

answered Oct 8, 2018 in AWS by Priyaj
• 58,100 points
2,897 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Is it possible to add a compatibility layer above AWS?

Well there are few tools like TyphoonAE ...READ MORE

answered Jan 15, 2019 in AWS by Archana
• 5,640 points
558 views
0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 58,100 points
3,450 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP