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:
- Trying to connect with the wrong key. Are you sure this instance is using this keypair?
- Trying to connect with the wrong username.
ubuntu
is the username for the ubuntu based AWS distribution, but on some others it'sec2-user
(oradmin
on some Debians, according to Bogdan Kulbida's answer)(can also beroot
,fedora
, see below) - 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
Linking to Modules Folder Gives Undefined Reference
In Bash How to Split a Column in Several Column of Fixed Dimension
Gnuplot Doesn't Work Through Ssh Command
How to Configure Acpi *.Asl for a Virtual Mdio-Gpio Device Connected to a I2C Gpio Expander
Run Bash Script in Raspberry Pi via Ifttt
Stack Smashing Code Not Working on Linux Kernel 2.6.38.7... Please Help
Omnisharp.Msbuild.Projectmanager Failed to Load Project on Linux
How to Set a Non-Standard Baudrate on a Serial Port Device on Linux
How to Draw 2D Diagram in Linux
How to Split Flv File by Size Using Ffmpeg or Mencoder or Smth Else
Average of Multiple Files Without Considering Missing Values
Script to Check for Process & Restart Program If Not Found
Perf Tool Stat Output: Multiplex and Scaling of "Cycles"
Calling Printf from Assembly Language on 64Bit and 32Bit Architecture Using Nasm