-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).
* ssh(1): support for cancelling local and remote port forwards via the
multiplex socket. Use ssh -O cancel -L xx:xx:xx -R yy:yy:yy user@host"
to request the cancellation of the specified forwardings
* support cancellation of local/dynamic forwardings from ~C commandline
如果您有较早的版本,则需要升级。如果您使用的是 Mac OS X,则可以安装 macports,然后使用升级:sudo port install openssh这会将其安装到/opt/local/bin.
正如我之前的回答说明,ssh 手册页
-O ctl_cmd
详细解释了、、或ctl_cmd
之一。check
forward
cancel
exit
您可以使用
ctl_cmd
来完成您想要的脚本自动化。您需要先创建一个ControlMaster
套接字,然后-S
像这样连接到远程主机:然后你可以从你的本地机器
forward
和cancel
你喜欢的端口。您可以使用一条命令转发多个端口:和/或一次处理一个:
我通过并排会话创建了一个要点,显示了
ssh -O ctl_cmd
实际操作;左侧是本地主机的端口forward
/cancel
,右侧是连接到远程主机的 ssh 输出:https://gist.github.com/raw/4265549/999d90b8f85190a41eed00e4d60d5d22da6c67b9/ssh-controlmaster-side-by-side.log
这些命令仅从OpenSSH 6.0开始可用:
如果您有较早的版本,则需要升级。如果您使用的是 Mac OS X,则可以安装 macports,然后使用升级:
sudo port install openssh
这会将其安装到/opt/local/bin
.