SSH & Remote Administration
Persistent SSH Sessions with ControlMaster
🧩 The Challenge
Establishing new SSH connections to the same host repeatedly causes high latency due to the overhead of repeated cryptographic handshakes. This is particularly noticeable when running multiple automation scripts or repeatedly logging into the same remote server in short succession.
💡 The Fix
Enable SSH multiplexing in your local configuration to reuse an existing network connection for subsequent sessions, eliminating the need for new authentication handshakes.
echo -e "Host *\n ControlMaster auto\n ControlPath ~/.ssh/sockets/%r@%h-%p\n ControlPersist 10m" >> ~/.ssh/config && mkdir -p ~/.ssh/sockets
⚙️ Why It Works
The ControlMaster directive tells the SSH client to share a single TCP connection for multiple sessions to the same host, while ControlPersist keeps the master connection open in the background for the specified duration.
🚀 Pro-Tip: Use the -O check flag with your SSH command to verify if a multiplexed master connection is currently active for a specific host.
Linux Tips & Tricks | © ngelinux.com | 7/7/2026
