带选项 -D 的 ssh 命令说明

Explanation of ssh command with option -D

我正在学习 ssh,我还没有理解以下带选项的命令 D

ssh -D 9999 username@remotehost.net

有人可以通过示例解释这个命令的确切作用以及它在什么时候有用吗?

这会将所有数据包从 localhost:9999 转发到 remotehost.net(在您的示例中)。简而言之,这是袜子代理。

来自 ssh 手册页:

Specifies a local “dynamic” application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as a SOCKS server. Only root can forward privileged ports. Dynamic port forwardings can also be specified in the configuration file.