0

A few days ago, I created a new key pair for a client's AWS EC2 instance. For some reason, I could no longer log in with the prior key pair I created. Immediately after creating a new SSH key pair, I named it and downloaded the .pem file to my iMac in ~/.ssh. The first SSH attempt worked perfectly -- I tunneled in without any issues or errors.

However, since then, I cannot SSH into this same instance, no matter what I do. I tried rebooting the instance and even created a new SSH key pair. To make sure AWS was seeing my .pem file, I ran ssh-add ~/.ssh/new.pem and keep getting Permission denied (publickey). I'm at a loss as to why this is happening. I can ssh into my own AWS EC2 instance without any trouble. I am also able to SSH into other client websites without any problems.

I have tried everything I can think of. Am I missing something?

Thanks in advance!

0

Wrong username to login? Depends on the AMI you launched, but you can try ec2-user.

  • Hi @hargut -- When I set this instance up, I chose Ubuntu Server 16.04, so the user is 'ubuntu'. What baffles me is that I have changed nothing and now I can't SSH in, even after rebooting the instance and creating a new PEM key pair. Also, I tried both 'ec2-user' and 'root', just to see if they would work. Neither did. – Brian Francoeur Aug 2 '18 at 20:04
  • ubuntu as user should be fine. Have you tried with ssh -i your-key-file.pem ubuntu@ip.ad.dr.es? – hargut Aug 2 '18 at 20:25
0

Here is a list of things to check:

1) Check the security group for this EC2 instance. You may have set it (as you should) to allow SSH from "My IP Address". But your IP address may have changed if you reset your router, etc. You may need to correct the IP Address that is allowed to connect.

2) In the AWS management console and examine the EC2 instance. It will tell you the name of the key file selected for that instance. Confirm that it is the file you expect it to be. Make sure your SSH configuration is using the correct private key file to match that public key file.

3) Check the instance's public IP address and/or public URL. If you applied an Elastic IP, both of these would have changed. You may need to correct the host name in your SSH connection.

Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.