SSH ForwardAgent正在接收“由远程主机closures连接”

我正在尝试使用SSH ForwardAgent连接到远程服务器,但我一直面临同样的问题:

 ssh_exchange_identification: Connection closed by remote host 

我已经安装我的〜/ .ssh / config如下:

 #Proxy Host my.remote.proxy.com Hostname IPProxy.IP.IP.IP User my.user IdentityFile ~/.ssh/id_rsa ForwardAgent yes #Remote server Host my.remote.server.com Hostname IPRemote.IP.IP.IP User my.user IdentityFile ~/.ssh/id_rsa ProxyCommand ssh [email protected] nc -w 10 %h %p 2> /dev/null 

我能正确地ssh到my.remote.proxy.com 。 我能够正确地从my.remote.proxy.com ssh使用SSH(和私人testing目的)到my.remote.server.com

我的问题是,我无法使用前置代理从主机ssh到my.remote.server.com

我已经为my.remote.proxy.commy.remote.server.com设置了/ etc / ssh / sshd_config,如下所示:

 AllowAgentForwarding yes AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes 

我检查了两台服务器正在使用带有前置代理的openssl的工作版本:

 openssh-7.4p1-13.el7_4.x86_64 openssh-clients-7.4p1-13.el7_4.x86_64 openssh-server-7.4p1-13.el7_4.x86_64 

来自my.remote.proxy.com的/ var / log / secure正在返回:

 Nov 15 04:39:07 [localhost] sshd[7866]: Accepted publickey for my.user Nov 15 04:39:07 [localhost] sshd[7866]: pam_unix(sshd:session): session opened for user my.user by (uid=0) Nov 15 04:39:08 [localhost] sshd[7869]: Received disconnect from IPPUBLIC port 61378:11: disconnected by user Nov 15 04:39:08 [localhost] sshd[7869]: Disconnected from IPPUBLIC port 61378 Nov 15 04:39:08 [localhost] sshd[7866]: pam_unix(sshd:session): session closed for user my.user 

my.remote.server.com上的/ var / log / secure没有显示任何内容。

解决的办法是用-W代替nc来转发连接,因为nc软件包没有远程安装在my.remote.server上

 ProxyCommand ssh [email protected] -W %h:%p 2> /dev/null 

-W host:port请求客户端上的标准input和输出通过安全通道转发到端口上的主机。 意味着-N,-T,ExitOnForwardFailure和ClearAllForwardings。 仅适用于协议版本2。