SSH RemoteForward 失败时通知客户端

SSH RemoteForward 失败时通知客户端

我正在使用 SSH 将远程计算机(客户端)上的端口转发到另一台计算机(服务器),使用(~/.ssh/config

主機客户端:

Hostname {ip}
    ...
    RemoteForward localhost:{port} localhost:{port}

问题是,即使服务器上没有监听程序,客户端也可以成功连接到localhost:port。唯一指示失败的就是服务器上的一条消息:connect_to localhost port {port}: failed.

有没有办法将此错误转发给客户端并终止连接?

答案1

如果 sshd 无法建立 LocalForward 指定的连接,则与本地端口的连接将立即关闭。如果 sshd 不这样做,则表明其行为不当。

以下是我遇到的情况:

1号航站楼:

dennis@lightning:~$ ssh -L 1111:localhost:1112 camel
Last login: Tue Jan 29 00:05:28 2013 from lightning.home.kaarsemaker.net
[dkaarsemaker@camel ~]$ channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused

每当我尝试连接终端 2 时,都会打印错误消息。

2 号航站楼:

dennis@lightning:~$ telnet localhost 1111
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

我发现我读错了问题,因为你使用了 RemoteForward。虽然这对我来说也有类似的结果,但立即断开连接:

dennis@lightning:~$ ssh -R 1111:localhost:1112 camel.ams6.corp.booking.com 
Last login: Sun Feb  3 11:43:07 2013 from lightning.home.kaarsemaker.net
[dkaarsemaker@camel ~]$ telnet localhost 1111
Trying 127.0.0.1...
connect_to localhost port 1112: failed.
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Connection closed by foreign host.

相关内容