我正在使用防火墙后面的服务器。 我已经build立了一个到互联网中间服务器的SSH隧道,如下所示:
remoteuser@behind_fw$ ssh -N -f -R 10002:localhost:22 middleuser@middle
但是我不能直接连接这个服务器,这是行不通的:
user@local$ ssh remoteuser@middle -p 10002
我必须分两步进行连接:
user@local$ ssh middleuser@middle middleuser@middle$ ssh remoteuser@localhost -p 10002
netstat -l在中间的输出:
tcp 0 0 localhost:10002 *:* LISTEN
但它应该是这样的:
tcp 0 0 *:10002 *:* LISTEN
我怎么能做到这一点?
这是在远程服务器上打开的隧道,该服务器需要在其/ etc / ssh / sshd_config 中将GatewayPorts设置为yes 。
取决于服务器的用户types,您可能需要使用“ 匹配”选项将该function限制到用户。
Match User middleuser GatewayPorts yes
请注意,您可能希望在sshd_config的末尾添加此匹配块,因为Match块会一直持续到另一个块开始,或者文件结束。
这就是说,而不是尝试我认为是一个稍微干净的解决scheme?
user@local$ ssh -N -f -L 10002:behind_fw:22 middleuser@middle user@local$ ssh remoteuser@localhost -p 10002
假设你正在使用OpenSSH,你需要指定绑定地址。 尝试像这样:
ssh -N -f -R *:10002:localhost:22 middleuser@middle
要么
ssh -N -f -R :10002:localhost:22 middleuser@middle
-R的签名是:
-R [bind_address:]port:host:hostport
在OpenSSH上。 出于安全原因,如果不指定它,它将默认为localhost。 您可能必须更改GatewayPort才能使其工作,具体取决于您的configuration。 请参阅SSH(1)了解更多信息。