您提供的示例是正确的,但有些误导。这应该工作:
ssh -L 8080:<remote-web-host-you-want-to-see>:80 remote-user@remote-ssh-server
例如,考虑一个运行ssh的远程盒,它可以访问此网页,我想在本地看到它:
http://192.168.1.2/index.html
为了在本地框上创建一个允许浏览到该远程页面的隧道,我在本地运行:
ssh -L 8080:192.168.1.2:80 user@remote-ssh-server
然后,我在一个网络浏览器中访问:
http:// localhost:8080 / index.html
如果您需要(或想要)省略端口说明符,则将需要以root用户身份打开隧道,因为80是“特权”端口(<1024):
sudo ssh -L 80:<remote-web-host-you-want-to-see>:80 remote-user@remote-ssh-server
然后,您可以在本地访问:
http://localhost/index.html
无需其他配置。
顺便说一句,这仅适用于您要在本地查看的单个主机。如果需要查看更多信息,则需要在其他端口上打开更多隧道,或者检查通过代理对所有远程主机的请求进行隧道传输的其他解决方案。
这是-L
来自的开关的第三种用法man ssh
:
-L [bind_address:]port:host:hostport
-L [bind_address:]port:remote_socket
-L local_socket:host:hostport
-L local_socket:remote_socket
Specifies that connections to the given TCP port or Unix socket on the
local (client) host are to be forwarded to the given host and port, or
Unix socket, on the remote side. This works by allocating a socket to
listen to either a TCP port on the local side, optionally bound to the
specified bind_address, or to a Unix socket. Whenever a connection is
made to the local port or socket, the connection is forwarded over the
secure channel, and a connection is made to either host port hostport,
or the Unix socket remote_socket, from the remote machine.
Port forwardings can also be specified in the configuration file. Only
the superuser can forward privileged ports. IPv6 addresses can be
specified by enclosing the address in square brackets.
By default, the local port is bound in accordance with the GatewayPorts
setting. However, an explicit bind_address may be used to bind the
connection to a specific address. The bind_address of “localhost”
indicates that the listening port be bound for local use only, while an
empty address or ‘*’ indicates that the port should be available from
all interfaces.