amazon-web-servicesamazon-ec2key-pair

AWS - Create new instance from AMI, but lost keys?


I have an AMI that I created a few weeks ago. I want to launch a new AWS EC2 instance and provide that AMI as the image. Problem is, I can't ssh into that box now.

I have tried to attach a new key pair when launching the new instance, but it's as if the configuration of the SSH keys on the box is ignoring my newly attached key pair.

Is there a way to overcome this issue?

I know my new key pair works, I've tested it on a totally blank new instance and I can SSH in just fine.

Any help is greatly appreciated!


Solution

  • The keypair is only copied to the Amazon EC2 instance the first time that the disk is booted. Since you have already booted from that disk (or a disk from which the image was made), it will not copy the keypair again.

    You will need to copy a new keypair to the /home/ec2-user/.ssh directory. This can be done by attaching the EBS volume to a different instance:

    See documentation: Connecting to Your Linux Instance if You Lose Your Private Key