Introduction
One of the most frustrating things when working on a server?
Your SSH session dies because of a brief Wi-Fi hiccup, idle timeout, or flaky connection.
Fix it forever in 30 seconds.
The Universal Fix: Edit Your SSH Config
This works on Linux, macOS, and Windows — and survives network glitches up to ~4–5 minutes.
Step 1: Create or Edit the SSH Config File
On Linux / macOS:
mkdir -p ~/.ssh
nano ~/.ssh/configOn Windows (PowerShell):
# Replace YourUsername with your actual Windows username
mkdir "$HOME\.ssh" -Force
notepad "$HOME\.ssh\config"Step 2: Add These Lines
sshHost *
ServerAliveInterval 120
ServerAliveCountMax 3
TCPKeepAlive yesSave and exit.
Done. That’s it.
What This Actually Does
| Setting | Meaning |
|---|---|
| Host * | Apply these rules to every SSH connection |
| ServerAliveInterval 120 | Every 2 minutes, your computer sends a tiny “I’m still here” packet |
| ServerAliveCountMax 3 | If 3 packets in a row fail → only then close the connection (~6 min) |
| TCPKeepAlive yes | Extra OS-level keepalive (helps with some routers/firewalls) |
Result: Your SSH session now survives:
- Wi-Fi switching
- Laptop sleep/wake
- Brief internet drops
- VPN reconnects
…without freezing or dying.
You're Now Unbreakable
From now on, when your internet blinks, your SSH session just… waits patiently.
No more “Connection reset by peer”
No more lost tmux sessions
No more rage
You’ve officially leveled up.
If this saved your sanity, share it with a fellow admin or subscribe to The Self Hosting Art.
Thank you for reading — stay connected!