24

I am trying to ssh to amazon ec2 instance from shell using the following command

ssh -vi sec.ppk ubuntu@ec2-xx.compute-1.amazonaws.com

but failed to connect

Here is the debug output generated by the above command

OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to ec2-xx.compute-1.amazonaws.com port 22.
debug1: Connection established.
debug1: identity file security1.ppk type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-4ubuntu5
debug1: match: OpenSSH_5.5p1 Debian-4ubuntu5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7
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<1024<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: Host 'ec2-xx.compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/ma/.ssh/known_hosts:9
debug1: ssh_rsa_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: sec.ppk
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key 'sec.ppk': 

Why it is asking passphrase for sec.ppk

What is the issue? Can anyone help?

Forgot to mention that i successfully made a connection using FileZilla with same above credentials

MA1
  • 2,767
  • 5
  • 35
  • 51
  • Because `sec.ppk` is encrypted with a passphrase. Have you tried entering it? – phihag Jan 24 '12 at 10:24
  • But i successfully made a connection using FileZilla with same above credentials using the same key. – MA1 Jan 24 '12 at 10:27
  • That means FileZilla has stored the passphrase in its settings. – phihag Jan 24 '12 at 11:21
  • But How? I never gave it anything except key file, user name and host . – MA1 Jan 24 '12 at 11:49
  • Oops, I overlooked the previous lines, which indicate a proprietary (or at least unsupported) key format. Have a look at Ravi's answer, which details that and how to convert your key to an openssh-compatible format. – phihag Jan 24 '12 at 12:05

3 Answers3

45

Try with

ssh -i /directory/keyname.pem ubuntu@ec2-xx.compute-1.amazonaws.com

Where .pem is the key pair file you've created while you setup your instance.

animuson
  • 53,861
  • 28
  • 137
  • 147
Hasanavi
  • 8,455
  • 2
  • 29
  • 35
7

For users who are new to AWS. The .ppk extension isn't compatible with openSSH and hence works only with FileZilla / PutTTY.

The easiest thing to do in this case is to install PutTTY and convert the .ppk to .pem using putty-tools. Here are the commands

sudo apt-get install putty
puttygen <path_to_key>/keyname.ppk -O private-openssh -o aws_key.pem
ssh -vi aws_key.pem ubuntu@<ip_address>

Hope this helps as a quick solution.

stochastic_zeitgeist
  • 1,037
  • 1
  • 14
  • 21
2

Sounds like you've created your private key with a passphrase. How did you create your key pair? Did you enter a passphrase when you created your private key?

You need to enter the passphrase you supplied while creating the key. and

debug1: read PEM private key done: type <unknown>

this suggests, your key was not recogined. Ideally you would get a method name like RSA.

Further check if you have a public key like id_rsa.pub somewhere, if yes, try using it and you will be in in case you don't remember your passphrase.

EDIT:

Okay, guess you are using ppk from amazon. To use your EC2-priv.ppk key, you will have to convert it into a format that OpenSSH will understand. You can go this with the PutTTYgen program. This will create a .pub file for you and then you can connect using that.

Ravi Bhatt
  • 3,147
  • 19
  • 21