EC2 Key Pair Troubleshooting

  • EC2 stores the public key (.pub) and you store the private key (.pem).

  • You use the private key, instead of a password, to securely access your instances.

  • Anyone who possesses your private keys can connect to your instances, so it's important that you store your private keys in a secure place.

What happens when you delete your EC2 key pair?

  • When you delete a key pair, you are only deleting the EC2 copy of the public key.

  • Deleting a key pair doesn't affect the private key on your computer or the public key on any instances that already launched using that key pair.

  • You can't launch a new instance using a deleted key pair, but you can continue to connect to any instances that you launched using a deleted key pair, as long as you still have the private key file.

Connect to your Linux instance if you lose your private key

  • If you lose the private key for an EBS-backed instance, you can regain access to your instance.

  • Stop the instance.

  • Detach its root volume/copy its AMI and attach it to another instance.

  • Modify the authorized_keys file with a new public key.

  • Move the volume/AMI back to the original instance.

  • Restart the instance.

Last updated

Was this helpful?