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,940 points
50 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
2 answers

Is it possible to ping AWS EC2 instance

Start by adding a new EC2 security group inbound ...READ MORE

answered Apr 9, 2018 in AWS by hemant
• 5,760 points
1,000 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
51 views
0 votes
1 answer
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 14, 2019 in AWS by Archana
• 5,600 points
47 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
• 57,530 points
633 views