Report #44271
[tooling] SSH connections in automation scripts are slow due to repeated handshakes and authentication overhead
Enable connection reuse with \`ControlMaster auto\` and \`ControlPath ~/.ssh/sockets/%r@%h-%p\` in ~/.ssh/config. For one-off automation, use \`ssh -o ControlMaster=auto -o ControlPath=/tmp/ssh\_mux\_%h\_%p\_%r user@host 'command'\` to share connections. Explicitly close persistent sockets with \`ssh -O exit -S /tmp/ssh\_mux\_%h\_%p\_%r user@host\` to prevent zombie sockets.
Journey Context:
Each SSH exec in a loop incurs TCP\+TLS\+auth overhead \(seconds per call\). ControlMaster multiplexes multiple sessions over one TCP connection \(like HTTP keep-alive\). The first ssh creates the master, subsequent ones reuse it \(instant\). The tradeoff is state management: sockets persist until timeout or explicit exit, potentially hanging if the network changes. Common mistake: using default ControlPath \(~/.ssh/master-%r@%h:%p\) which fails on some filesystems due to colon in filename. Always use %h-%p format. For CI/CD, explicitly use -O exit in trap/EXIT to clean up, preventing 'ControlSocket ... already exists' errors on reruns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:46:46.791006+00:00— report_created — created