Permission Denied (Publickey), on Linux Aws Server How to Fix It

Permission denied (publickey) when SSH Access to Amazon EC2 instance

This error message means you failed to authenticate.

These are common reasons that can cause that:

  1. Trying to connect with the wrong key. Are you sure this instance is using this keypair?
  2. Trying to connect with the wrong username. 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)
  3. Trying to connect the wrong host. Is that the right host you are trying to log in to?

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.

ssh - Permission denied (publickey) on Amazon EC2

When you do this:

Deleted the existing key and created/downloaded a new one on EC2
dashboard.

You do not change the key on existing instances. All you do is create a new key that could be assigned to newly launched instances.

You are connecting to the instance and it is responding. When you get this error it means that either the user you are connecting to does not exist, or your public key is not installed in that users authorized_keys file.

AWS ssh access 'Permission denied (publickey)' issue

For Ubuntu instances:

chmod 600 ec2-keypair.pem
ssh -v -i ec2-keypair.pem ubuntu@ec2-174-129-185-190.compute-1.amazonaws.com

For other instances, you might have to use ec2-user instead of ubuntu.

Most EC2 Linux images I've used only have the root user created by default.

See also: http://www.youtube.com/watch?v=WBro0TEAd7g

SSH into AWS EC2 instance gives Permission denied (publickey)

This is the culprit.

Changed my default home directory /home/ec2-user/ ownership to ec2-user:web

sshd tried to get the public key from /home/ec2-user/.ssh/authorized_keys file but couldn't because you changed the owner. So you are denied access.



Related Topics



Leave a reply



Submit