How do I change the key-pair of an AWS instance if I lost my PEM file?

I lost the pem file and deleted the key-pair under which an instance in currently running. I want to still use that server though. I created a new key pair but I don't know how to assign it to that instance.


You can go to your instance and say " launch instance like this". This time it will create clone of your EC2 instance. You can specify new key for this instance. Make sure you select the same security group.

This way, you will not loose your data and you will gain access to your ec2 instance with new key.

Note: If your old instance had EIP then you need to re-assign that EIP to new instance.

If your instance does not have EIP then you need to make sure you update your other instances with new private IP address or URL so that connectivity will not be broken.

If there are any EBS volumes attached to your previous instance then you need to attach to new instance.

Termination of old EC2 can be done as last step!!!.


Unless you have another way to log into the instance, you're not going to be able to access it. Amazon does not have your private key and cannot log in to your instance.

If you still need your data, disconnect the EBS-volume and attach it to a new EC2-instance.