Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS - Disconnected : No supported authentication methods available (server sent :publickey)

SSH to my AWS server just broke for both Putty and Filezilla. I'm making some effort for this post to be a comprehensive troubleshooting list, so if you share links to other stack overflow pages, I'll edit them into the question.

Disconnected : No supported authentication methods available (server sent :publickey) 


The error is familiar from when I set up the connection almost a year ago. If you're setting up AWS SSH for the first time, these address the most common problems:

  • Wrong username: Disconnected : No supported authentication methods available (server sent :publickey)
  • Incorrect .ppk file: Unable to connect to amazon server using putty

However, the only thing I could think that would impact a previously working system is:

  • Wrong IP: Restarting an AWS instance (or creating an image) is not guaranteed to keep the same IP address. This would obviously have to be updated in putty.

What other possibilities are there?

Solution to this one (per the accepted post below) is that for AWS EC2 all 3 of these need to have proper permissions (777 not ok for any of these). Here's one example that works:

/home/ec2-user/ - 700 /home/ec2-user/.ssh/ - 600 /home/ec2-user/.ssh/authorized_keys - 600 

/var/log/secure will tell you which one is throwing an error, consult this video tutorial to get access if you're completely locked out: http://d2930476l2fsmh.cloudfront.net/LostKeypairRecoveryOfLinuxInstance.mp4

like image 902
AvadData Avatar asked Jul 05 '14 14:07

AvadData


People also ask

Why is my AWS instance not connecting?

The following are common reasons why EC2 Instance Connect might not work as expected: EC2 Instance Connect doesn't support the OS distribution. The EC2 Instance Connect package isn't installed on the instance. There are missing or incorrect AWS Identity and Access Management (IAM) policies or permissions.

Can I connect to EC2 instance Permission denied Publickey?

To solve the "Permission denied (publickey)" error when trying to SSH into an EC2 instance: Open your terminal in the directory where your private key is located and change its permissions to only be readable by the current user.


2 Answers

I had the same problem, by accident mistake. I'll share it here, in case someone may have made the same mistake.

Basic steps, as others described.

  1. Download putty and puttygen, or the putty package and install it.
  2. Get the .pem file from your AWS EC2 instance.
  3. Use puttygen to convert the .pem file so that you'll have a private key --- mistake happened here. I chose "Conversions" tab from PuttyGen, and load my .pem file. After loading pem file, here DO NOT hit "Generate", instead directly "Save private key". That's the key you need. If you click Generate, you'll have a totally different pair of keys.
  4. In putty, use [email protected], and load the private key at SSH/Auth

Good luck!

like image 107
Tony Xu Avatar answered Sep 25 '22 21:09

Tony Xu


Comprehensive answer is here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

Your problem can be related to incorrect login which varies depending on AMIs. Use following logins on following AMIs:

  • ubuntu or root on ubuntu AMIs
  • ec2-user on Amazon Linux AMI
  • centos on Centos AMI
  • debian or root on Debian AMIs
  • ec2-user or fedora on Fedora
  • ec2-user or root on: RHEL AMI, SUSE AMI, other ones.

If you are using OS:

  • Windows - get PEM key from AWS website and generate PPK file using PuttyGen. Then use Putty to use the PPK (select it using left-column: Connection->SSH->Auth: Private key for authorization)
  • Linux - run: ssh -i your-ssh-key.pem login@IP-or-DNS

Good luck.

like image 25
Witold Kaczurba Avatar answered Sep 23 '22 21:09

Witold Kaczurba