# ansible ssh error to ec2-instance

**URL:** <https://forum.ansible.com/t/ansible-ssh-error-to-ec2-instance/28185>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 28, 2018, 1:45pm UTC](https://forum.ansible.com/t/ansible-ssh-error-to-ec2-instance/28185 "2018-07-28T13:45:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhan0618](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@madhan0618](https://forum.ansible.com/u/madhan0618)\
**Post date:** [July 28, 2018, 1:45pm UTC](https://forum.ansible.com/t/ansible-ssh-error-to-ec2-instance/28185/1 "2018-07-28T13:45:13Z")

</div>

I am able to ssh to an ec2 instance using putty and .ppk file.

when trying to do the same from build server, i am getting ssh error

things that i have tried

1. inventory file:

[aws-hosts]  
10.20.30.40 [changed ip for the post]

[aws-hosts:vars]  
ansible\_ssh\_private\_key\_file=/tmp/devhosts.ppk

then ran  
ansible aws-hosts -u ec2-user -i invent -m ping

getting the below error

ESTABLISH SSH CONNECTION FOR USER: ec2-user  
SSH: EXEC ssh -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey,keyboard-interactive -o ControlMaster=auto -o ControlPersist=300 -o StrictHostKeyChecking=no -o ‘IdentityFile=“/tmp/devhosts.ppk”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=120 -o ControlPath=/home/xxxxx/.ansible/cp/7f5a8fa6ee xxxxxx ‘/bin/sh -c ‘"’"’/usr/bin/python && sleep 0’“'”‘’  
xxxxxxxx | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “SSH Error: data could not be sent to remote host "xxxxxxxxx". Make sure this host can be reached over ssh”,  
“unreachable”: true  
}

replaced ip with ‘xxxxxxx’

1. tried to replace the ppk file in the inventory file with .pem file still same error

2. tried --key-file in the ansible command line instead of the inventory file.

3. tried --private-key in the ansible command line

get the same error for all.

---

<div class="post-metadata">

**Author:** ![bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@bala](https://forum.ansible.com/u/bala)\
**Post date:** [July 28, 2018, 1:51pm UTC](https://forum.ansible.com/t/ansible-ssh-error-to-ec2-instance/28185/2 "2018-07-28T13:51:46Z")

</div>

try this sed -i ‘/[ssh\_connection/ s/$/ \nscp\_if\_ssh = True/’ ansible.cfg

---

<div class="post-metadata">

**Author:** ![madhan0618](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@madhan0618](https://forum.ansible.com/u/madhan0618)\
**Post date:** [July 28, 2018, 3:16pm UTC](https://forum.ansible.com/t/ansible-ssh-error-to-ec2-instance/28185/3 "2018-07-28T15:16:39Z")

</div>

sed -i ‘/[ssh\_connection/s/$/\nscp\_if\_ssh=True/’ ansible.cfg  
sed: -e expression #1, char 39: unterminated address regex

i added this line manually  
nscp\_if\_ssh=True

but still same error

---

<div class="post-metadata">

**Author:** ![bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@bala](https://forum.ansible.com/u/bala)\
**Post date:** [July 28, 2018, 3:31pm UTC](https://forum.ansible.com/t/ansible-ssh-error-to-ec2-instance/28185/4 "2018-07-28T15:31:57Z")

</div>

its not nscp , just scp pl check
