Here is my very simple piece of code aiming at connecting to a ssh server through a local socks proxy on port 8888
import subprocess
host = 'X.x.X.x'
port = 22
subprocess.call( [
"ssh",
"-o", "ProxyCommand='/bin/socat - SOCKS4A:127.0.0.1:%h:%p,socksport=8888'",
"-p", "{}".format(port),
"root@{}".format(host)
])
However, I got an ugly error message when trying executing.
/bin/bash: /bin/socat - SOCKS4A:127.0.0.1:X.x.X.x:22,socksport=8888: No such file or directory
ssh_exchange_identification: Connection closed by remote host
What is trange is that is work when copy pasting directly the full comand line on the shell.
It's a bit late but I just had the same problem when running with execvp. You need to remove the quotes around the ProxyCommand, e.g.
import subprocess
host = 'X.x.X.x'
port = 22
subprocess.call( [
"ssh",
"-o", "ProxyCommand=/bin/socat - SOCKS4A:127.0.0.1:%h:%p,socksport=8888",
"-p", "{}".format(port),
"root@{}".format(host)
])
These are removed by your shell when you run on the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With