I can connect to my Amazon EC2 instance via the pem
file that I've been given.
I do something like this
ssh -i <mykeyname>.pem ubuntu@<myexternalip>
and it works ok.
But now I need a passwordless login to my instance, so I create a key pair as shown here
and send my .pub
file to my remote instance and put it under the .ssh
directory with the name authorized_keys
but I still can't connect!
I keep getting an error message:
Permission denied (publickey).
Could anyone tell me what I'm doing wrong? Are all other forms of logging in (apart from .pem files) disallowed by default on EC2 Instances?
thanks in advance.
It turns out it wasn't an SSH problem at all. The problem was that, when I call sudo
, i forgot that the user changes to root... and obviously I hadn't set up keys for the root user so it kept failing on me...
I solved it by using sudo -u actual_user
instead.
Thanks to cmn on git@freenode for helping me see this.