aef*_*aef 11 security ssh vnc port-forwarding multiplexing
我刚刚发现了 OpenSSH 的 ControlMaster/ControlPath 功能,它允许您使用单个 SSH 连接来运行多个终端。
由于我经常使用 SSH 来使用端口转发来获得加密和经过身份验证的 VNC 会话,我立即意识到您无法将端口转发添加到已经建立连接的远程服务器。这很糟糕。
有时后来我发现您可以通过在正在运行的 SSH 终端会话中键入 ~C 来规避此限制。这将打开一个命令行,允许您添加或删除端口转发。
我现在的问题是:如何在使用 ControlMaster/ControlPath 功能的现有 SSH 会话上添加端口转发,而无需访问该 SSH 会话中的终端会话。我需要这个来启用我的脚本,该脚本启动一个安全的隧道 VNC 连接,以便我添加并稍后删除其端口转发。
(我知道我可以使用终端多路复用器,例如 GNU Screen 或 tmux,实际上我已经在这样做了。但出于多种原因,我喜欢只使用一个 SSH 会话的想法。)
acu*_*ich 13
这其实很简单。只需将 ctl_cmd 添加-O forward到您现有的命令中,因此:
ssh -M -L5555:localhost:22 remotehost
Run Code Online (Sandbox Code Playgroud)
变成:
ssh -O forward -M -L5555:localhost:22 remotehost
Run Code Online (Sandbox Code Playgroud)
该ssh手册页讨论-O ctl_cmd的选项:
-O ctl_cmd
Control an active connection multiplexing master process. When the -O option is
specified, the ctl_cmd argument is interpreted and passed to the master process.
Valid commands are: “check” (check that the master process is running), “forward”
(request forwardings without command execution), “exit” (request the master to
exit), and “stop” (request the master to stop accepting further multiplexing
requests).
Run Code Online (Sandbox Code Playgroud)
当然,这假设您已ControlMaster yes在~/ssh/config文件或-M命令行中启用。