Kirill Platonov
Kirill Platonov
Mar 15, 2017

Restore AWS EC2 instance private key

In case when you lost private keys from AWS EC2 instances you will need a way to restore it. Unfortunately you can't just change instance private key in AWS Management Console. The easiest way to do it which I found is through Amazon Machine Image (AMI). Basically all you need to do is recreate you instance from AMI and set new private key to it. Below I describe required steps to do it.

Steps to change EC2 key pair

  1. Shut down your instance aws-ec2-private-keys-1.png

  2. Create AMI for that instance and provide some meaningful name for them aws-ec2-private-keys-2.png aws-ec2-private-keys-3.png

  3. Go to “Images > AMIs”. You need to launch instance with the same type from created AMI aws-ec2-private-keys-4.png

  4. On the last step of launching you will be asked about key pair. So it’s time to create/chose private key which you want to use with this instance aws-ec2-private-keys-5.png

  5. After that you need go to “Network & Security > Elastic IPs” and disassociate ip from old instance and associate with created instance aws-ec2-private-keys-6.png aws-ec2-private-keys-7.png

  6. And finally terminate old instance aws-ec2-private-keys-8.png

Well, now you have instance with you new private key and you can connect to it thought ssh.