SSHing from AWS Instance to AWS Instance using .pem asks for passphrase

3.1k Views Asked by At

I am trying to ssh/scp into my AWS instance however it always asks for a passphrase for the .pem file even though there wasn't one set. I have spent hours researching and I have tried everything. Its chmod'ed 400 ( tried 600 and 777 too -no luck)

This is a what I get after pressing enter on the passphrase/password :

  The authenticity of host '****************' can't be established.
    ECDSA key fingerprint is ************************.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '*********' (ECDSA) to the list of known hosts.
    Enter passphrase for key 'new_bro.pem':
    Permission denied (publickey).
    lost connection

and this is a ssh -v message

ubuntu@ip-10-0-0-221:~$ ssh -v -i new_bro.pem ubuntu@***********
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 *************** port 22.
debug1: Connection established.
debug1: identity file new_bro.pem type -1
debug1: identity file new_bro.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA ***********************
debug1: Host '*************' is known and matches the ECDSA host key.
debug1: Found key in /home/ubuntu/.ssh/known_hosts:2
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: new_bro.pem
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key 'new_bro.pem':
debug1: No more authentication methods to try.
Permission denied (publickey).
ubuntu@ip-10-0-0-221:~$

I have tried doing it from different machine - same thing. I can login using Putty after converting .pem to .ppk

Please help

2

There are 2 best solutions below

0
On

Your pem file is corrupt, or not in the correct format for a pem key

A couple of commands to test it

openssl rsa -check -in new_bro.pem -noout should say "RSA key ok"

ssh-keygen -y -e -f new_bro.pem makes a public key from the private key, compare with the public key on the remote

0
On

for me, it was because I didn't include

-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----

while copying pem file.