This error message means you failed to authenticate.
These are common reasons that can cause that:
ubuntu
is the username for the ubuntu based AWS distribution, but on some others it's ec2-user
(or admin
on some Debians, according to Bogdan Kulbida's answer)(can also be root
, fedora
, see below) Note that 1.
will also happen if you have messed up the /home/<username>/.ssh/authorized_keys
file on your EC2 instance.
About 2.
, the information about which username you should use is often lacking from the AMI Image description. But you can find some in AWS EC2 documentation, bullet point 4.
:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
Use the ssh command to connect to the instance. You'll specify the private key (.pem) file and user_name@public_dns_name. For Amazon Linux, the user name is ec2-user. For RHEL5, the user name is either root or ec2-user. For Ubuntu, the user name is ubuntu. For Fedora, the user name is either fedora or ec2-user. For SUSE Linux, the user name is root. Otherwise, if ec2-user and root don't work, check with your AMI provider.
Finally, be aware that there are many other reasons why authentication would fail. SSH is usually pretty explicit about what went wrong if you care to add the -v
option to your SSH command and read the output, as explained in many other answers to this question.
In this case the problem arises from lost Key Pair. About this:
You can follow these steps:
In general, remember you have to allow your EC2 instance to accept inbound SSH traffic.
To do this, you have to create a specific rule for the Security Group of your EC2 instance. You can follow these steps.
Hope this can help someone as helped me.
This is how I solved the problem
ssh -i <key> ec2-user@<ec2 ip>
I solved the problem just putting sudo
before
sudo ssh -i mykey.pem myec2.amazonaws.com
But the proper solution is to change the ownership first, and then connect as a normal user as Janus Troelsen said below. In my case it would be:
chown wellington:wellington key.pem
Try using
sudo ssh -i mykey.pem ubuntu@<ec2_ip_public_dns>
OR
sudo ssh -i mykey.pem ec2-user@<ec2_ip_public_dns>
Another possible cause of this error:
When user's home directory is group writeable, the user cannot login.
(Reproduced on Ubuntu instance.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With