按组限制ssh隧道端口访问

我的理解是,当创build到远程机器的SSH隧道时,端口在该机器上打开供任何人使用,并连接回我的本地盒子(不仅仅是打开隧道的用户)。 有没有办法将访问远程机器上打开的端口限制到指定的unix? 我想这可能是通过iptables规则或其他TCP / IP端口的限制,但我不完全确定。

谢谢

您可以使用iptables owner模块来匹配始发套接字的UID或GID,但是这仅适用于本地(即从远程计算机)发出的数据包。

 % ssh -fNR 20022:localhost:22 localhost % sudo iptables --append OUTPUT --destination 127.0.0.1 --protocol tcp --dport 20022 --match owner \! --uid-owner mgorven --jump REJECT % sudo iptables -nvL OUTPUT Chain OUTPUT (policy ACCEPT 40 packets, 6349 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:20022 ! owner UID match 1000 reject-with icmp-port-unreachable % telnet 127.0.0.1 20022 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1 ^] telnet> Connection closed. % sudo telnet 127.0.0.1 20022 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused