限制 SSH 服务器隧道端口

限制 SSH 服务器隧道端口

我有一个运行 OpenSSH 的 SSH 服务器。我想使用它来设置 SOCKS 服务器,以便我在中国的朋友可以使用它来访问 Twitter 等网站。我想强制执行两个限制:1. 禁止 shell 访问,2. 仅允许端口 80 和 443。

我的问题是,如何强制执行第二个限制?我尝试在 /home/tunuser/.ssh/authorized_keys 中放入以下行:permitopen=":80",permitopen=":443",no-pty ...

我使用 ssh -D 选项,浏览器使用 SOCKS 代理。ssh 客户端成功登录,但我的 Web 浏览器无法建立隧道。ssh 服务器上的错误消息显示不允许建立隧道。

当我删除两个“permitopen”选项后,我的浏览器就可以成功浏览了。

openssh 是否支持“仅限制端口,允许任何主机”?

答案1

抱歉,无法wildcard使用hostnames

No pattern matching is performed on the specified hostnames, 
they must be literal domains or addresses.

手册页permitopen

permitopen="host:port"
         Limit local ``ssh -L'' port forwarding such that it may only connect 
to the specified host and port.  IPv6 addresses can be specified by enclosing
the address in square brackets.  Multiple permitopen options may be applied 
separated by commas.  No pattern matching is performed on the specified                 
hostnames, they must be literal domains or addresses.  A port specification 
of * matches any port.

相关内容