Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No such file or directory" when call ProxyCommand through Python script

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.

like image 394
mytrexisnice Avatar asked Sep 10 '26 08:09

mytrexisnice


1 Answers

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.

like image 126
Paul Edwards Avatar answered Sep 12 '26 20:09

Paul Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!