Five ~/.ssh/config patterns I keep reusing
Every new laptop gets the same handful of blocks in ~/.ssh/config. Here they are, so that I stop rewriting them from memory.
1. Short aliases
Host web
HostName 203.0.113.10
User deploy
Port 2201
ssh web instead of remembering an address, a user and a port. scp and rsync understand the alias too.
2. Jump hosts
Host db
HostName 10.0.0.12
ProxyJump web
The database box has no public address; ssh db goes through web without an agent being forwarded anywhere.
3. One key per host, and only that key
Host git-work
HostName git.example.com
IdentityFile ~/.ssh/work_ed25519
IdentitiesOnly yes
IdentitiesOnly yes is the line that stops "Too many authentication failures" when the agent holds a dozen keys and offers all of them first.
4. Keepalives behind NAT
Host *
ServerAliveInterval 30
ServerAliveCountMax 4
Home routers forget idle connections. Thirty seconds is enough to keep a session open through most of them, and four missed replies end a dead one in two minutes instead of hanging forever.
5. Connection sharing
Host *
ControlMaster auto
ControlPath ~/.ssh/cm-%r@%h:%p
ControlPersist 10m
The second ssh to the same host opens instantly over the first connection. After changing anything about a host, close the master with ssh -O exit web, or the old settings stay in use for ten more minutes.
Order matters: ssh takes the first value it sees for each option, so the specific Host blocks go above Host *.