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
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
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).
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.