Issue
I create ec2-instance on the AWS server:
Now I try to connect to the server with putty.
- First of all, I downloaded the PPK for instance:
- In the next I created a connection with putty:
- After I launch connection and set the username as ec2-user:
- in the result I got the error:
How to correctly connect to the ec2 instance with PPK?
Solution
What I understand from the question is that you did launch an EC2 instance successfully and afterwards you generated a new SSH key pair which does not have any connection to the already created EC2 instance.
What you should have done is to create a new key when the instance was launched:
OR select an existing key:
Now, the easiest way to solve this problem is to terminate the EC2 instance and recreate it with your existing key pair. You should be able to chose wlifter-ppk
from the dropdown.
If, for some reason, you don't want to do this or it is not possible to terminate and relaunch the instance, there are several ways to rescue the instance and attach an existing SSH key.
I. Manually rescue the instance:
- From Putty convert you
.ppk
to RSA public key. - Use EC2 Instance Connect or Session Manager to connect to your instance.
- Locate the
.ssh/authorized_keys
file. For Amazon Linux instances this can be found in/home/ec2-user/.ssh
folder. - Open
authorized_keys
, append the new RSA public key and save the file. - Connect to the instance using Putty.
II. Use EC2Rescue tool https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-boot-issues/
Answered By - Ervin Szilagyi