通过pyhton scrip调用ProxyCommand时“没有这样的文件或目录”

2024-09-28 22:50:51 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的一段非常简单的代码,旨在通过8888端口上的本地socks代理连接到ssh服务器

    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)
    ])

但是,我在尝试执行时收到了一条丑陋的错误消息

    /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

什么是trange是直接在shell上复制粘贴完整命令行时的工作


Tags: 端口代码import服务器formathost代理bin