Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change keypairs ec2 running instance

Tags:

amazon-ec2

Hello i've made a big mistake with may key pairs on a ec2 Instance. I can't connect with sftp and putty because the private key is wrong.

How can i get access to my instances or change the key pairs at the console?

like image 669
Sandor Farkas Avatar asked May 11 '11 14:05

Sandor Farkas


2 Answers

Steps:

  • Stop the instance
  • Create a new instance (which comes with a new volume and new key pair)
  • Detach your old volume from its instance and attach it to the new instance you just created along the new volume (so now you have two volumes attached to your new instance)
  • Start the new instance and mount the old volume (/dev/sdf is the default).
  • Copy contents of /home/ec2-user/.ssh and /etc/ssh from the new volume to the old volume
  • Stop the new instance and attach old volume to its main instance
  • Start your old instance

Now you can use the new key pair you generated for the new instance, to connect to your old one.

This did work for me and just a few notes:

  • Both instances were from same type and distribution
  • Instances shall be in the same Amazon region and zone
  • If you use elastic IP, re-attach elastic IP address as it will get released
like image 131
bolbol Avatar answered Oct 26 '22 16:10

bolbol


I think you need to rebuild the instance with a old(correct) key pair.

http://docs.amazonwebservices.com/AWSSecurityCredentials/1.0/AboutAWSCredentials.html#EC2KeyPairs

like image 38
gandil Avatar answered Oct 26 '22 16:10

gandil