允许 SSH 反向隧道 (-R),但不允许本地转发 (-L)?

Uta*_*ead 2 ssh ssh-tunnel

我们有一个拥有远程服务器的客户,他想限制我们可以访问服务器的时间(大多数客户我们在本地启动了按需访问)。

我正在为他们设置一个脚本,这样他们就可以启动它,它将使用特定帐户通过 SSH 连接到我们这边并设置远程隧道 (-R),这样我们就可以从那时起访问他们的服务器。

我的问题是我不确定如何正确锁定它以便我们可以访问反向隧道,但他不能同时创建本地转发 (-L)。 sshd_config允许我限制转发。

Match User user1
    GatewayPorts       yes
    AllowTcpForwarding yes
    PermitOpen         127.0.0.1:12345
Run Code Online (Sandbox Code Playgroud)

现在,这将允许他创建一个反向隧道,以便我们可以使用 YYY 协议连接回它们,但同时,它也允许他在同一端口上创建一个返回我们的本地隧道。

我是否正确理解事物?有没有办法允许反向隧道,但拒绝所有本地转发?

Tom*_*mek 5

sshd_config 手册页包含所有内容:

 AllowTcpForwarding
         Specifies whether TCP forwarding is permitted.  The available
         options are yes (the default) or all to allow TCP forwarding, no
         to prevent all TCP forwarding, local to allow local (from the
         perspective of ssh(1)) forwarding only or remote to allow remote
         forwarding only.  Note that disabling TCP forwarding does not
         improve security unless users are also denied shell access, as
         they can always install their own forwarders.
Run Code Online (Sandbox Code Playgroud)

在您的情况下,您可能需要:

Match User user1
    GatewayPorts       yes
    AllowTcpForwarding remote
    PermitOpen         127.0.0.1:12345
Run Code Online (Sandbox Code Playgroud)

并且可能 PermitOpen 与远程端口转发无关。

  • 我专门查看了 AllowTcpForwarding 并没有看到该选项。非常感谢!*叹气*,现在我明白为什么了。我搜索了手册页并为 FreeBSD 找到了那个(第一个结果)。你100%正确,谢谢。 (2认同)