# Unable to ssh onto newly created ec2 instance

**URL:** <https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685>\
**Category:** Ansible Project\
**Created:** [October 15, 2013, 6:33pm UTC](https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685 "2013-10-15T18:33:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Peiser](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Marc\_Peiser](https://forum.ansible.com/u/Marc_Peiser)\
**Post date:** [October 15, 2013, 6:33pm UTC](https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685/1 "2013-10-15T18:33:39Z")

</div>

Hi all

I’m trying to get a playbook to create an ec2 instance, run a bunch of stuff and then delete the instance based on the ec2 example in the docs. I’m having an issue where after it waits for ssh to come up, it fails to ssh into the host. Manually sshing to the instance as root works just fine from the cmd line after the playbook fails.

Here is the output with -vvvv [http://pastebin.com/FQY53BB6](http://pastebin.com/FQY53BB6)

My hosts file has the following:

[localhost]  
127.0.0.1 ansible\_ssh\_user=root

Any ideas what I’m doing wrong?

Thanks,  
Marc

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 15, 2013, 7:15pm UTC](https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685/2 "2013-10-15T19:15:10Z")

</div>

From the log it looks like it is cycling through your public keys and failing

1. debug1: Offering RSA public key: /root/.ssh/id\_rsa

2. debug3: send\_pubkey\_test

3. debug2: we sent a publickey packet, wait for reply

4. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password

5. debug1: Trying private key: /root/.ssh/id\_dsa

6. debug3: no such identity: /root/.ssh/id\_dsa

7. debug1: Trying private key: /root/.ssh/id\_ecdsa

8. debug3: no such identity: /root/.ssh/id\_ecdsa

9. debug2: we did not send a packet, disable method

10. debug1: No more authentication methods to try.

When you ssh to your instance what key are you using?  
Try $ ssh -i /root/.ssh/ and make sure that works if you believe one of the keys it tried is valid

I don’t believe it’s the problem but you will need to set “host\_key\_checking = False” in your ansible.cfg for 1.2+ since your new instance won’t be in your known\_hosts file.

Finally. if you want to be more explicit, pass these options when you run the play:

$ ansible-playbook … --user -e “ansible\_ssh\_private\_key\_file=/full/path/to/your/key.pem”

-John

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [October 15, 2013, 10:39pm UTC](https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685/3 "2013-10-15T22:39:38Z")

</div>

Marc,

Could we see your playbook or an anonymized snippet at least? I'm curious about how you are referencing the dynamically added hosts in your play.

Thanks,  
James

---

<div class="post-metadata">

**Author:** ![Marc\_Peiser](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Marc\_Peiser](https://forum.ansible.com/u/Marc_Peiser)\
**Post date:** [October 15, 2013, 10:44pm UTC](https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685/4 "2013-10-15T22:44:24Z")

</div>

I only have one key available:

optaplanner@optaplanner:~$ ls -l .ssh/  
total 16  
-rw-rw-r-- 1 optaplanner optaplanner 52 Oct 15 06:54 config  
-rw------- 1 optaplanner optaplanner 1675 Oct 14 21:35 id\_rsa  
-rw-r–r-- 1 optaplanner optaplanner 410 Oct 14 21:35 id\_rsa.pub  
-rw-r–r-- 1 optaplanner optaplanner 3978 Oct 15 20:09 known\_hosts

And I can ssh onto the box using that key:

optaplanner@optaplanner:~$ ssh [root@54.251.71.221](mailto:root@54.251.71.221) -i ~/.ssh/id\_rsa  
Last login: Tue Oct 15 21:04:21 2013 from 54.254.54.51  
[root@ip-10-128-87-77 ~]#

I tried adding “host\_key\_checking = False” to ansible.cfg but still get the same result. I also have “StrictHostKeyChecking no” to my ssh config so that I’m not prompted to accept the new host key every time.

Also tried running “$ ansible-playbook --user root -e “ansible\_ssh\_private\_key\_file=/home/optaplanner/.ssh/id\_rsa” site.yml -vvvv” but get the same thing (see below).

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\<122.248.220.172\> ESTABLISH CONNECTION FOR USER: root  
\<122.248.220.172\> EXEC [‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/optaplanner/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, u’IdentityFile=/home/optaplanner/.ssh/id\_rsa’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=root’, ‘-o’, ‘ConnectTimeout=10’, u’122.248.220.172’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1381876732.87-94895521671279 && echo $HOME/.ansible/tmp/ansible-1381876732.87-94895521671279’”]  
fatal: [122.248.220.172] =\> SSH encountered an unknown error. The output was:  
OpenSSH\_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012  
debug1: Reading configuration data /home/optaplanner/.ssh/config  
debug1: /home/optaplanner/.ssh/config line 3: Applying options for \*  
debug1: Reading configuration data /etc/ssh/ssh\_config  
debug1: /etc/ssh/ssh\_config line 19: Applying options for \*  
debug1: auto-mux: Trying existing master  
debug1: Control socket “/home/optaplanner/.ansible/cp/ansible-ssh-122.248.220.172-22-root” does not exist  
debug2: ssh\_connect: needpriv 0  
debug1: Connecting to 122.248.220.172 [122.248.220.172] port 22.  
debug2: fd 3 setting O\_NONBLOCK  
debug1: fd 3 clearing O\_NONBLOCK  
debug1: Connection established.  
debug3: timeout: 9983 ms remain after connect  
debug3: Incorrect RSA1 identifier  
debug3: Could not load “/home/optaplanner/.ssh/id\_rsa” as a RSA1 public key  
debug1: identity file /home/optaplanner/.ssh/id\_rsa type 1  
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048  
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048  
debug1: identity file /home/optaplanner/.ssh/id\_rsa-cert type -1  
debug1: Remote protocol version 2.0, remote software version OpenSSH\_5.3  
debug1: match: OpenSSH\_5.3 pat OpenSSH\*  
debug1: Enabling compatibility mode for protocol 2.0  
debug1: Local version string SSH-2.0-OpenSSH\_5.9p1 Debian-5ubuntu1  
debug2: fd 3 setting O\_NONBLOCK  
debug3: load\_hostkeys: loading entries for host “122.248.220.172” from file “/home/optaplanner/.ssh/known\_hosts”  
debug3: load\_hostkeys: loaded 0 keys  
debug1: SSH2\_MSG\_KEXINIT sent  
debug1: SSH2\_MSG\_KEXINIT received  
debug2: kex\_parse\_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1  
debug2: kex\_parse\_kexinit: [ecdsa-sha2-nistp256-cert-v01@openssh.com](mailto:ecdsa-sha2-nistp256-cert-v01@openssh.com),ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,ssh-dss  
debug2: kex\_parse\_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se  
debug2: kex\_parse\_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se  
debug2: kex\_parse\_kexinit: [hmac-md5,hmac-sha1,umac-64@openssh.com](mailto:hmac-md5,hmac-sha1,umac-64@openssh.com),hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96  
debug2: kex\_parse\_kexinit: [hmac-md5,hmac-sha1,umac-64@openssh.com](mailto:hmac-md5,hmac-sha1,umac-64@openssh.com),hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96  
debug2: kex\_parse\_kexinit: [none,zlib@openssh.com](mailto:none,zlib@openssh.com),zlib  
debug2: kex\_parse\_kexinit: [none,zlib@openssh.com](mailto:none,zlib@openssh.com),zlib  
debug2: kex\_parse\_kexinit:  
debug2: kex\_parse\_kexinit:  
debug2: kex\_parse\_kexinit: first\_kex\_follows 0  
debug2: kex\_parse\_kexinit: reserved 0  
debug2: kex\_parse\_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1  
debug2: kex\_parse\_kexinit: ssh-rsa,ssh-dss  
debug2: kex\_parse\_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se  
debug2: kex\_parse\_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se  
debug2: kex\_parse\_kexinit: [hmac-md5,hmac-sha1,umac-64@openssh.com](mailto:hmac-md5,hmac-sha1,umac-64@openssh.com),hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96  
debug2: kex\_parse\_kexinit: [hmac-md5,hmac-sha1,umac-64@openssh.com](mailto:hmac-md5,hmac-sha1,umac-64@openssh.com),hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96  
debug2: kex\_parse\_kexinit: [none,zlib@openssh.com](mailto:none,zlib@openssh.com)  
debug2: kex\_parse\_kexinit: [none,zlib@openssh.com](mailto:none,zlib@openssh.com)  
debug2: kex\_parse\_kexinit:  
debug2: kex\_parse\_kexinit:  
debug2: kex\_parse\_kexinit: first\_kex\_follows 0  
debug2: kex\_parse\_kexinit: reserved 0  
debug2: mac\_setup: found hmac-md5  
debug1: kex: server-\>client aes128-ctr hmac-md5 none  
debug2: mac\_setup: found hmac-md5  
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  
debug2: dh\_gen\_key: priv key bits set: 130/256  
debug2: bits set: 531/1024  
debug1: SSH2\_MSG\_KEX\_DH\_GEX\_INIT sent  
debug1: expecting SSH2\_MSG\_KEX\_DH\_GEX\_REPLY  
debug1: Server host key: RSA 94:b2:2c:4e:9e:8e:31:3d:3f:a2:4e:7d:5d:77:e4:5c  
debug3: load\_hostkeys: loading entries for host “122.248.220.172” from file “/home/optaplanner/.ssh/known\_hosts”  
debug3: load\_hostkeys: loaded 0 keys  
Warning: Permanently added ‘122.248.220.172’ (RSA) to the list of known hosts.  
debug2: bits set: 517/1024  
debug1: ssh\_rsa\_verify: signature correct  
debug2: kex\_derive\_keys  
debug2: set\_newkeys: mode 1  
debug1: SSH2\_MSG\_NEWKEYS sent  
debug1: expecting SSH2\_MSG\_NEWKEYS  
debug2: set\_newkeys: mode 0  
debug1: SSH2\_MSG\_NEWKEYS received  
debug1: Roaming not allowed by server  
debug1: SSH2\_MSG\_SERVICE\_REQUEST sent  
debug2: service\_accept: ssh-userauth  
debug1: SSH2\_MSG\_SERVICE\_ACCEPT received  
debug2: key: /home/optaplanner/.ssh/id\_rsa (0x7fe755d24a60)  
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password  
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password  
debug3: preferred gssapi-with-mic,gssapi-keyex,hostbased,publickey  
debug3: authmethod\_lookup gssapi-with-mic  
debug3: remaining preferred: gssapi-keyex,hostbased,publickey  
debug3: authmethod\_is\_enabled gssapi-with-mic  
debug1: Next authentication method: gssapi-with-mic  
debug1: Unspecified GSS failure. Minor code may provide more information  
Credentials cache file ‘/tmp/krb5cc\_1001’ not found

debug1: Unspecified GSS failure. Minor code may provide more information  
Credentials cache file ‘/tmp/krb5cc\_1001’ not found

debug1: Unspecified GSS failure. Minor code may provide more information

debug1: Unspecified GSS failure. Minor code may provide more information  
Credentials cache file ‘/tmp/krb5cc\_1001’ not found

debug2: we did not send a packet, disable method  
debug3: authmethod\_lookup gssapi-keyex  
debug3: remaining preferred: hostbased,publickey  
debug3: authmethod\_is\_enabled gssapi-keyex  
debug1: Next authentication method: gssapi-keyex  
debug1: No valid Key exchange context  
debug2: we did not send a packet, disable method  
debug3: authmethod\_lookup publickey  
debug3: remaining preferred: ,publickey  
debug3: authmethod\_is\_enabled publickey  
debug1: Next authentication method: publickey  
debug1: Offering RSA public key: /home/optaplanner/.ssh/id\_rsa  
debug3: send\_pubkey\_test  
debug2: we sent a publickey packet, wait for reply  
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password  
debug2: we did not send a packet, disable method  
debug1: No more authentication methods to try.  
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

TASK: [Download EPEL repo] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
FATAL: no hosts matched or all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/home/optaplanner/site.retry

122.248.220.172 : ok=0 changed=0 unreachable=1 failed=0  
127.0.0.1 : ok=3 changed=1 unreachable=0 failed=0

optaplanner@optaplanner:~/optaplanner-ansible$ ssh [root@122.248.220.172](mailto:root@122.248.220.172)  
[root@ip-10-135-39-36 ~]#

Regards,  
Marc

---

<div class="post-metadata">

**Author:** ![Marc\_Peiser](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Marc\_Peiser](https://forum.ansible.com/u/Marc_Peiser)\
**Post date:** [October 15, 2013, 10:47pm UTC](https://forum.ansible.com/t/unable-to-ssh-onto-newly-created-ec2-instance/13685/5 "2013-10-15T22:47:14Z")

</div>

Hi James,

Sure thing, here’s it is:
