最近我经常使用 SSH 客户端的 ControlMaster 功能,它允许我使用单个 SSH-TCP 连接进行多个 shell 和端口转发到同一个远程系统。最烦人的是,打开的第一个 shell 进程自动成为 ControlMaster。这意味着,如果此进程终止,则使用控制主连接的所有其他 shell 和端口转发将变得不可用。
我真的很想当远程系统的第一个 ssh 命令会产生一个额外的后台进程时,只要仍然有使用 ControlMaster 连接的连接,它就会保持连接,这样我就可以简单地关闭实际的 shell,而不必冒其他崩溃的风险连接。理想情况下,后台 ControlMaster 进程甚至可以配置为在最终关闭之前等待新 shell 或端口转发使用 ControlMaster 的时间。
有没有办法让ssh客户端做这样的事情?我知道我可以在使用 ssh 创建第一个 shell 之前手动创建这样的连接,但我明确希望这会自动发生,否则我肯定会时不时忘记这样做。
让包装脚本来做这件事也不是那么容易,因为我经常在 .ssh/config 中使用配置的远程服务器名称的简写,而 ControlMaster 套接字是使用 USERNAME@NETWORK_NAME:NETWORK_PORT 作为名称创建的。因此,包装器需要完全理解 .config/ssh 才能按预期工作。
Dan*_*son 10
您应该使用 ControlPersist 配置选项。
ControlPersist
When used in conjunction with ControlMaster, specifies that the
master connection should remain open in the background (waiting
for future client connections) after the initial client connec?
tion has been closed. If set to “no”, then the master connection
will not be placed into the background, and will close as soon as
the initial client connection is closed. If set to “yes”, then
the master connection will remain in the background indefinitely
(until killed or closed via a mechanism such as the ssh(1) “-O
exit” option). If set to a time in seconds, or a time in any of
the formats documented in sshd_config(5), then the backgrounded
master connection will automatically terminate after it has
remained idle (with no client connections) for the specified
time.
Run Code Online (Sandbox Code Playgroud)
ControlPersist no是默认行为,正如您所描述的。我使用ControlPersist 4h来允许后台会话定期清理自己。
归档时间: |
|
查看次数: |
1318 次 |
最近记录: |