Don’t re-authenticate every time you SSH to the same host
SSH & Remote Administration
Don’t re-authenticate every time you SSH to the same host
🧩 The Challenge
Ever had to SSH into a server, run a quick command, then disconnect? Only to realize you need to `scp` a file over, and then maybe `ssh` back in to check the logs? Each time, you’re hitting your key’s password or waiting for the connection. And it’s a real time killer, especially when you’re jumping in and out of the same box twenty times an hour.
💡 The Fix
There’s an SSH config option that lets you reuse an existing connection to the same host for all subsequent commands. Once the first connection is established, any new SSH, SCP, or SFTP commands to that host instantly hop on the existing channel, skipping the auth dance entirely. It’ll save you a ton of keystrokes and mental overhead.
Host myappserver
Hostname 192.168.1.100
User appuser
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h:%p
ControlPersist 1h
⚙️ Why It Works
This setup tells SSH to open a persistent connection (a “master” connection) when you first connect to `myappserver`. All follow-up commands to `myappserver` then piggyback on that initial, authenticated session. And the `ControlPersist` setting keeps that master connection alive for up to an hour even after all active shells close, ready for your next command.
🚀 Pro-Tip: Drop that `Host` block into your `~/.ssh/config` file and make sure `mkdir -p ~/.ssh/sockets` is run.
Linux Tips & Tricks | © ngelinux.com | 10/25/2026
