大网数据广告活动
服务器运维问答

Allow SSH Reverse Tunneling (-R), but not Local Forwarding (-L)?

· 52CE 我爱测

We have a customer with a remote server who wants to restrict times we can access the server (most customers we have on-demand access initiated locally). I'm setting up a script for them so they can just kick it off and it will S…

问题原文

原帖链接 · UtahJarhead · CC BY-SA 4.0

We have a customer with a remote server who wants to restrict times we can access the server (most customers we have on-demand access initiated locally).

I'm setting up a script for them so they can just kick it off and it will SSH to our side with a specific account and set up the Remote Tunnel (-R) so we can hit their server from that point.

My issue is that I'm not sure how to lock it down properly so we can access a reverse tunnel, but he can't simultaneously create a Local Forward (-L). sshd_config allows me to restrict forwards.

Match User user1
    GatewayPorts       yes
    AllowTcpForwarding yes
    PermitOpen         127.0.0.1:12345

Now, this would allow him to create a reverse tunnel so we can connect back to them using protocol YYY, but at the same time, it would also allow him to create a local tunnel back to us on the same port.

Am I understanding things correctly? Is there a way to allow Reverse Tunnels, but deny all Local Forwards?

已采纳解答

原帖链接 · Tomek · CC BY-SA 4.0

sshd_config man page has it all:

 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.

In your case you likely need:

Match User user1
    GatewayPorts       yes
    AllowTcpForwarding remote
    PermitOpen         127.0.0.1:12345

and possibly PermitOpen is irrelevant to remote port forwarding.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-11-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。