Report #92924
[tooling] Checking or terminating existing SSH multiplexed connections \(ControlMaster\) programmatically
Use ssh -O check to verify if a ControlMaster connection exists \(exits 0 if running\), and ssh -O exit to explicitly kill the master connection. These operate on the ControlPath socket without establishing a new login shell.
Journey Context:
When using ControlMaster for connection multiplexing to speed up repeated SSH operations, scripts often need to verify if the persistent connection is alive before depending on it, or explicitly tear it down to force re-authentication \(e.g., after key changes\). Simply checking for the socket file existence is unreliable \(stale sockets\). The -O flag sends a request to the master process over the socket; 'check' returns exit status 0 if the master is responsive, 'exit' requests graceful shutdown. This avoids race conditions and parsing of ps output in automation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:33:34.664019+00:00— report_created — created