自OpenSSH 5.4以来,有一个名为natcat模式的新function,它允许您将本地SSH客户端的STDIN和STDOUT绑定到可通过远程SSH服务器访问的TCP端口。 只需调用ssh -W [HOST]:[PORT]
从理论上讲,这应该是在每个主机SSHconfiguration中使用ProxyCommand设置的理想select,这在以前经常与nc (netcat)命令一起使用。 ProxyCommand允许您将本地计算机与目标SSH服务器之间的代理configuration为代理,例如,如果目标SSH服务器隐藏在防火墙之后。
现在的问题是,它不是在工作,而是在我的脸上抛出一个神秘的错误信息:
Bad packet length 1397966893. Disconnecting: Packet corrupt
这里是我的~/.ssh/config的摘录:
Host * Protocol 2 ControlMaster auto ControlPath ~/.ssh/cm_socket/%r@%h:%p ControlPersist 4h Host proxy-host proxy-host.my-domain.tld HostName proxy-host.my-domain.tld ForwardAgent yes Host target-server target-server.my-domain.tld HostName target-server.my-domain.tld ProxyCommand ssh -W %h:%p proxy-host ForwardAgent yes
正如你在这里看到的,我使用了ControlMasterfunction,所以我不必打开每个主机的多个SSH连接。
我testing过的客户端机器是Ubuntu 11.10(x86_64),代理主机和目标服务器都是Debian Wheezy Beta 3(x86_64)机器。
当我调用ssh target-server时发生错误。 当我用-vvv标志调用它时,这里是我另外得到的:
OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011 debug1: Reading configuration data /home/aef/.ssh/config debug1: Applying options for * debug1: Applying options for target-server.my-domain.tld debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Applying options for target-server.my-domain.tld debug1: auto-mux: Trying existing master debug1: Control socket "/home/aef/.ssh/cm_socket/[email protected]:22" does not exist debug2: ssh_connect: needpriv 0 debug1: Executing proxy command: exec ssh -W 192.0.2.195:22 gateway-host.my-domain.tld debug1: identity file /home/aef/.ssh/id_rsa type -1 debug1: identity file /home/aef/.ssh/id_rsa-cert type -1 debug1: identity file /home/aef/.ssh/id_dsa type -1 debug1: identity file /home/aef/.ssh/id_dsa-cert type -1 debug1: identity file /home/aef/.ssh/id_ecdsa type -1 debug1: identity file /home/aef/.ssh/id_ecdsa-cert type -1 debug1: permanently_drop_suid: 1000 Host key fingerprint is 1a:2b:3c:4d:5e:6f:7a:8b:9c:ad:be:cf:de:ed:fe:ef +--[ECDSA 521]---+ | | | | | | | | | | | | | | | | | | +-----------------+ debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-3 debug1: match: OpenSSH_6.0p1 Debian-3 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1 debug2: fd 5 setting O_NONBLOCK debug2: fd 4 setting O_NONBLOCK debug3: load_hostkeys: loading entries for host "192.0.2.195" from file "/home/aef/.ssh/known_hosts" debug3: load_hostkeys: loaded 0 keys debug3: load_hostkeys: loading entries for host "192.0.2.195" from file "/etc/ssh/ssh_known_hosts" debug3: load_hostkeys: found key type ECDSA in file /etc/ssh/ssh_known_hosts:49 debug3: load_hostkeys: found key type RSA in file /etc/ssh/ssh_known_hosts:50 debug3: load_hostkeys: loaded 2 keys debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa debug1: SSH2_MSG_KEXINIT sent Bad packet length 1397966893. Disconnecting: Packet corrupt
更新:现在用-vvv代替-v输出。
我终于明白了这是什么意思。 当proxy-host和target-server上的ControlMaster都打开时,它似乎是OpenSSH中的一个错误。 然而,至less有这两个解决方法:
在尝试连接到target-server之前,确保已经有一个连接到proxy-host连接。 这将使错误消失,一切按预期工作。 你可以通过手动连接到proxy-host来做到这一点。
为ProxyCommand禁用ControlMaster ,如ProxyCommand ssh -o "ControlMaster no" -W %h:%p proxy-host 。 这也将摆脱这个问题,但它会创build一个新的连接到proxy-host的每个连接使用完全相同的ProxyCommand 。
这个真正的问题是ControlPersist因为这个选项出现在OpenSSH 5.6中 。
你应该考虑把你的openssh服务器升级到>=5.6或者直接从客户端configuration文件中删除这个指令。
问候