# failed to open a SFTP connection, -c ssh connects but gives me errors

**URL:** <https://forum.ansible.com/t/failed-to-open-a-sftp-connection-c-ssh-connects-but-gives-me-errors/12091>\
**Category:** Ansible Project\
**Created:** [November 17, 2012, 12:24am UTC](https://forum.ansible.com/t/failed-to-open-a-sftp-connection-c-ssh-connects-but-gives-me-errors/12091 "2012-11-17T00:24:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nflacco](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nflacco](https://forum.ansible.com/u/nflacco)\
**Post date:** [November 17, 2012, 12:24am UTC](https://forum.ansible.com/t/failed-to-open-a-sftp-connection-c-ssh-connects-but-gives-me-errors/12091/1 "2012-11-17T00:24:53Z")

</div>

I’m having trouble with paramiko/sftp, and using the -c ssh option gets me one step further but still results in an error. I’ve been running on OSX but created a fresh LinuxMint VM in VirtualBox with all the latest and greatest stuff, and duplicated the issues I saw in OSX. The -c ssh looks slightly different though. For reference, I’m running python 2.7 on both Linux and OSX, and I’m trying to access an EC2 instance.

I’ve tried executing a simple shell command (-m shell -a 'echo “HELLO”) and a ping (-m ping). I have also tried a simple playbook and gotten the same errors.

**LinuxMint (VM), Pyth**

Paramiko

> $ansible prod --user=ec2-user --private-key=key.pem -m shell -a ‘echo “Hello”’  
> [www.myserver.com](http://www.myserver.com) | FAILED =\> failed to open a SFTP connection

SSH

> $ansible prod --user=ec2-user --private-key=key.pem -m shell -a ‘echo “Hello”’ -c ssh  
> [prod1.v2.pixieplug.com](http://prod1.v2.pixieplug.com) | FAILED =\> failed to transfer file to /home/ec2-user/.ansible/tmp/ansible-1353110320.71-241956472283584/command:

> Couldn’t read packet: Connection reset by peer

**OSX**

Paramiko

> $ansible prod --user=ec2-user --private-key=key.pem -m shell -a ‘echo “Hello”’  
> [prod1.v2.pixieplug.com](http://prod1.v2.pixieplug.com) | FAILED =\> failed to open a SFTP connection

SSH

> $ansible prod --user=ec2-user --private-key=key.pem -m shell -a ‘echo “Hello”’ -c ssh  
> [www.myserver.com](http://www.myserver.com) | FAILED =\> failed to transfer file to /home/ec2-user/.ansible/tmp/ansible-1353110453.09-107376501006560/command:  
> Connecting to [www.myserver.com](http://www.myserver.com)…  
> // motd that I expect from my server, so it got in //  
> subsystem request failed on channel 0  
> Connection closed

**OSX, Playbooks**

Paramiko

> $ansible-playbook test.yml --user=ec2-user --private-key=key.pem  
> PLAY [prod] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [[www.myserver.com](http://www.myserver.com)] =\> failed to open a SFTP connection  
> TASK: [print hello world] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> FATAL: no hosts matched or all hosts have already failed – aborting
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> [www.myserver.com](http://www.myserver.com) : ok=0 changed=0 unreachable=1 failed=0

SSH

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [November 17, 2012, 2:22am UTC](https://forum.ansible.com/t/failed-to-open-a-sftp-connection-c-ssh-connects-but-gives-me-errors/12091/2 "2012-11-17T02:22:03Z")

</div>

Shot in the dark here, but can you transfer anything to the host via a  
manual sftp command line call (i.e. not using ansible) ? You may want  
to check the machines /etc/ssh/sshd\_config file to see if you have the  
sftp subsystem configured correctly.

---

<div class="post-metadata">

**Author:** ![nflacco](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nflacco](https://forum.ansible.com/u/nflacco)\
**Post date:** [November 17, 2012, 3:38am UTC](https://forum.ansible.com/t/failed-to-open-a-sftp-connection-c-ssh-connects-but-gives-me-errors/12091/3 "2012-11-17T03:38:25Z")

</div>

You are correct!

Looks like default sftp info in the /etc/ssh/ssh\_config file in CentOS is incorrect ([http://blog.firsthand.ca/2009/01/cannot-connect-with-capistrano-or-sftp.html](http://blog.firsthand.ca/2009/01/cannot-connect-with-capistrano-or-sftp.html)).

Replace in /etc/ssh/ssh\_config:

> `# The default is incorrect`  
> `# Subsystem sftp /usr/lib/openssh/sftp-server`  
> `Subsystem sftp /usr/libexec/openssh/sftp-serv`er

And restart sshd
