Debug “Permission denied" issue

How to debug “Permission denied (publickey)” issue while logging into EC2 (SSH) ?

Usually this error occurs when we give the wrong user name.

We can deal with this error by providing the correct user name.

Note: Admin user for Ubuntu instances is “ubuntu”
For Amazon linux instances, it is “ec2-user”
For Red Hat Enterprise Linux, it is “ root”

Example:

  1. For Ubuntu instances:

ssh ubuntu@ec2-54-205-63-83.compute-1.amazonaws.com –i (identity file’s path i.e., ec2-keypair.pem)

  1. For amazon linux instances:

ssh ec2-user@ec2-54-205-63-83.compute-1.amazonaws.com –i (identity file’s path)

i.e., Use ec2-user instead of ubuntu
Linux images in ec2 mostly have the default admin user created.

If you still facing issue you deattach the root volume and attach it to different instance and add change keypair

You need to make sure the keys must have only read permission.

You need to make sure keys have read only permission 400