Ubuntu – ssh with .pem file to amazon instance Permission denied (publickey)

amazon ec2serverssh

I am trying to login to instance on amazon using, my ".pem" file has 600 privileges:

ssh -v -i FTPServer.pem ec2-user@ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com

i tried all possible users "root/ubuntu/ec2-user.." i always receive the following:

    OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com [xx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file FTPServer.pem type -1
debug1: identity file FTPServer.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-8
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-6ubuntu2
debug1: match: OpenSSH_5.1p1 Debian-6ubuntu2 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 0f:ad:a5:01:e1:75:82:fa:54:bd:56:53:34:d9:7e:6b
debug1: Host 'ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/myhome/.ssh/known_hosts:6
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: Downloads/FTPServer.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: FTPServer.pem
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

Best Answer

Unless you provided a custom list of users upon creation, the default 'ubuntu' user should still exist, and the EC2 key was put on that user, as a typical configuration would get.

To make it work on other users, you need to take the lines from /home/ubuntu/.ssh/authorized_keys and put them into the file /home/$USER/.ssh/authorized_keys (where $USER is the username you are specifically trying to make work with that key).

Based on your comments, though, this isn't your EC2 instance, and you were just given the .pem without actual login instructions. You need to reach out to the administrator (the person who set up the EC2 instance) and request login instructions, as well as instruct them to verify that the public key for the .pem is available in the .ssh/authorized_keys file in the home directory for the user they want you to login as.