Why does SSH disconnect on its own (Broken pipe) — three causes and how to fix them

You log into a server, get distracted for ten minutes, come back — the terminal doesn't respond. You hit Enter, nothing. A minute later this appears:
client_loop: send disconnect: Broken pipe
Or the terminal just hangs for good. First we'll rescue the frozen window, then go through the three causes almost everyone runs into. Starting with the most common.
First: how to close a frozen SSH session
Ctrl+C won't help here: SSH dutifully forwards it to the server, and nothing reaches the server. SSH has its own secret exit. Press, in order:
- Enter
- ~ (tilde)
- . (period)
The connection closes immediately and you're back in your own terminal. It's SSH's built-in emergency button. It only works at the start of a line — hence Enter first.
Cause 1. The router forgot a quiet connection
The most common one. Between you and the server sit routers and firewalls. They remember every open connection. But if nothing travels over one for a while, they decide it's dead and drop it from memory. You're reading a log in silence — and the connection is already "forgotten".
How to check. It only drops after you've been idle. While you type, it's stable. Walk away for 5–15 minutes — gone.
How to fix. Ask SSH to send signs of life itself. Open ~/.ssh/config on your computer (create it if it doesn't exist) and add:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
Now every 60 seconds the client sends the server a short "still there?". The connection never sits idle, so the router doesn't forget it. And if the server really is gone, after three unanswered checks SSH disconnects on its own. You'll see a clear Timeout, server ... not responding instead of a window frozen forever.
Why isn't this on by default? The system has a similar mechanism at the network level, but on Linux it fires once every two hours by default. Far too rarely for a home router.
Cause 2. The laptop slept or switched networks
You closed the lid, moved from Wi-Fi to mobile data, turned on a VPN. Your network address changed — and the SSH connection is tied to the old one. No setting can save it: to the server, that was a different computer.
How to check. The drop lines up with sleep, moving around, or switching networks.
How to fix. Instead of keeping the connection alive, make losing it harmless:
- Work on the server inside tmux. When the connection drops, your session stays alive on the server, and after reconnecting you're right back where you were. Step by step in how to use tmux.
- For constant roaming there's mosh — an ssh replacement that survives network changes and sleep. You install it on both your computer and the server.
An important consequence. A command started directly in the SSH window usually dies along with it when the connection drops. Run long installs or scripts in tmux. And anything that must run all the time — a bot or a server — make it a service: we covered how in what is a daemon.
Cause 3. The server kicks you out itself
Less common, but annoying. Sometimes it's not the network but the server, following its own idle rule. Company and hosting servers sometimes enable this on purpose.
How to check. If this message appeared right before the disconnect
timed out waiting for input: auto-logout
— that's the shell on the server. It's controlled by the TMOUT variable. Check it: echo $TMOUT. The number is how many seconds of silence it tolerates. If there's no message but the drop always comes after exactly the same time, look at the SSH server settings: ClientAliveInterval in /etc/ssh/sshd_config.
How to fix. On your own server you can remove TMOUT from the shell config files where it's set, or raise the value. How the shell reads those files at login, we covered in .bashrc or .bash_profile. On someone else's server the rule may be intentional — then tmux saves you again.
How to tell which cause is yours
Connect with a verbose log:
ssh -v user@server
SSH will print every step it takes. When the drop happens, the last lines tell you who closed the connection: the network (Broken pipe, Connection reset), the check timeout (not responding), or the server itself (Connection closed by remote host). The basics of how SSH connects at all are in what is SSH.
FAQ
Do I set ServerAliveInterval on the server?
No, it's a client setting — your computer. The server has a mirror twin, ClientAliveInterval. The client one is usually enough.
Will this help if VS Code Remote keeps disconnecting?
Yes. The Remote-SSH extension uses the same ~/.ssh/config, so ServerAliveInterval works for it too.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





