-3

I am trying to connect to EC2 via SSH this way:

ssh -i path_to_pem ec2-user@PublicDNS

But when I do it, I get the message Permission denied (publickey). and the connection is closed.

How should be correctly set up permissions?

Thanks

user984621
  • 46,344
  • 73
  • 224
  • 412

2 Answers2

1

Permission denied (publickey) doesn't indicate a problem with the filesystem permissions of your private key located at path_to_pem, rather is just the SSH error message for indicating that it is unable to identify/match a key for/with the challenge provided by the SSH server running on your Amazon EC2 instance.

You are trying to log in as ec2-user, which indicates you are using the Amazon Linux AMI, is this actually correct? For example, the widely used Ubuntu AMIs facilitate a user ubuntu instead, so given your example you'd log in as follows:

chmod 600 path_to_pem
ssh -i path_to_pem ubuntu@PublicDNS

If you are using an AMI other than the Amazon Linux AMI or one of the official Ubuntu ones, you'd need to look up the required user in the accompanying documentation (other than trying the former default root user).

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
0

I was not being able to log in through the user ec2-user neither ubuntu, so I tried to log in as

ssh -i path_to_pem root@PublicDNS

which printed me out the name of the user I should use -> then it worked.

user984621
  • 46,344
  • 73
  • 224
  • 412
  • Any particular reason why you don't consider [my answer](http://stackoverflow.com/a/16328711/45773) to be helpful and correct then? After all, I identified the problem (wrong user), mentioned `root` as an option as well, plus hinted towards the AMI vendor documentation (I figure from your [follow up question](http://stackoverflow.com/q/16339761/45773) that you are using a Bitnami AMI, which easily yields the `bitnami` user as per [How can I use SSH ...?](http://wiki.bitnami.com/cloud/how_to_connect_to_your_amazon_instance#How_can_I_use_SSH_to_connect_to_my_server_on_Linux_or_Mac_OS_X.3f)). – Steffen Opel May 02 '13 at 20:45