为什么 SSH 允许我在同一端口上创建多个本地隧道?

为什么 SSH 允许我在同一端口上创建多个本地隧道?

如您所见,当我尝试创建另一个隧道监听已使用的本地端口时,我收到错误消息,但隧道已创建。当有另一个进程正在使用给定端口时,我可以强制 ssh 不在给定端口上创建隧道吗?

┌─[wakatana@~] [79 files, 89Mb]
└──> ps -elf | grep 'ssh -fN'
1 S wakatana     4263     1  0  80   0 - 10660 -      May02 ?        00:00:00 ssh -fN -L 5901:localhost:5901 [email protected]
0 S wakatana     6340  4754  0  80   0 -  1959 -      00:22 pts/7    00:00:00 grep --color=auto ssh -fN

┌─[wakatana@~] [79 files, 89Mb]
└──> ssh -fN -L 5900:192.168.1.1:3389 [email protected]
┌─[wakatana@~] [79 files, 89Mb]
└──> ps -elf | grep 'ssh -fN'
1 S wakatana     4263     1  0  80   0 - 10660 -      May02 ?        00:00:00 ssh -fN -L 5901:localhost:5901 [email protected]
1 S wakatana     6371     1  0  80   0 - 10355 -      00:22 ?        00:00:00 ssh -fN -L 5900:192.168.1.1:3389 [email protected]
0 S wakatana     6381  4754  0  80   0 -  1959 -      00:22 pts/7    00:00:00 grep --color=auto ssh -fN

┌─[wakatana@~] [79 files, 89Mb]
└──> ssh -fN -L 5900:192.168.1.3:3389 [email protected]
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5900
Could not request local forwarding.
┌─[wakatana@~] [79 files, 89Mb]
└──> ps -elf | grep 'ssh -fN'
1 S wakatana     4263     1  0  80   0 - 10660 -      May02 ?        00:00:00 ssh -fN -L 5901:localhost:5901 [email protected]
1 S wakatana     6371     1  0  80   0 - 10355 -      00:22 ?        00:00:00 ssh -fN -L 5900:192.168.1.1:3389 [email protected]
1 S wakatana     6391     1  0  80   0 - 10355 -      00:23 ?        00:00:00 ssh -fN -L 5900:192.168.1.3:3389 [email protected]
0 R wakatana     6401  4754  0  80   0 -  1958 -      00:23 pts/7    00:00:00 grep --color=auto ssh -fN

答案1

我试着思考如何整理你的问题,但没有时间。我可以为你回答:你需要将“ExitOnForwardFailure”选项设置为“是”。

$ ssh -fN -o ExitOnForwardFailure=yes -L 5900:192.168.1.1:3389 [email protected]
$ ssh -fN -o ExitOnForwardFailure=yes -L 5900:192.168.1.3:3389 [email protected] 
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5900
Could not request local forwarding.
$ ps auwwx | grep ssh | grep 1111
daniel          94948   0.0  0.0  2461204    520   ??  Ss    2:56pm   0:00.00 ssh -Nf -o ExitOnForwardFailure=yes -L 5900:192.168.1.1:3389 MY.PUB.IP.ADDR

相关内容