1 Answer
- Newest
- Most votes
- Most comments
0
Hi Ray,
Unfortunately, once a private key PEM file is downloaded from AWS, it cannot be re-downloaded. Here are a few steps you can take to solve your problem:
-
Accessing the EC2 Instance with the Original Key:
- Since you can't download the
pc_key.pemagain, you need to find a way to access your original PC to get thepc_key.pemfile. You might consider using a remote desktop or VPN to access your PC if that's an option.
- Since you can't download the
-
Creating a New Key Pair and Adding It to the Instance:
- You mentioned you created a new key pair (
laptop_key.pem). To use this key, you need to add the new public key to your instance. - First, access your EC2 instance using the
pc_key.pemon your original PC. - Add the public key from
laptop_key.pemto the~/.ssh/authorized_keysfile on your instance. Here’s how:
Once logged in, open thessh -i pc_key.pem ubuntu@mysite.comauthorized_keysfile:
Add the contents of the new public key (found innano ~/.ssh/authorized_keyslaptop_key.pem.pub) to this file. Save and exit.
- You mentioned you created a new key pair (
-
Using SSH Agent Forwarding:
- If you have another machine that has the
pc_key.pemfile, you can use SSH agent forwarding to connect to your instance from your laptop. This requires setting up SSH agent forwarding on the machine with the key and on your laptop.
- If you have another machine that has the
-
Using AWS Systems Manager Session Manager:
- If your instance has the SSM agent installed and configured, you can use the AWS Systems Manager Session Manager to connect to your instance without needing the PEM key. This would allow you to update the
authorized_keysfile with your new key.
- If your instance has the SSM agent installed and configured, you can use the AWS Systems Manager Session Manager to connect to your instance without needing the PEM key. This would allow you to update the
Here is a link to AWS documentation on Setting Up Session Manager.
I hope one of these solutions helps you regain access to your EC2 instance.
ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
ref2: https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2reset.html
ref3: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/replacing-key-pair.html
Relevant content
- asked 3 years ago
- AWS OFFICIALUpdated 2 years ago

Thanks Vitor. Since I am overseas and can't reach my pc which has the original key, step 1 to 3 can't be applied by myself but they are helpful. Step 4 may be ok but I don't want to change the original key though. Eventually I manage to have someone else to access to the server from another PC.