You step away for a coffee, come back, press a key, and the terminal answers with client_loop: send disconnect: Broken pipe. The session is gone, along with whatever you'd half typed. An ssh broken pipe almost always means the connection went quiet long enough for something on the path (your router, a firewall, or the server itself) to forget it existed.
Quick Answer: Add
ServerAliveInterval 60andServerAliveCountMax 3to~/.ssh/configon your computer, then setClientAliveInterval 60andClientAliveCountMax 3on the server and reload sshd. Both ends now send a small encrypted heartbeat every 60 seconds, so routers and firewalls never see the link as idle. Run long jobs insidetmuxso a dropped connection can't kill them.
Last verified: November 2026, against OpenSSH 10.6 (upstream), Ubuntu 26.04 LTS (OpenSSH 10.2p1) and Ubuntu 24.04 LTS (OpenSSH 9.6p1).
Our engineers resolve 20-30 client server issues every day, and dropped terminal sessions turn up often enough that we've settled on a fixed order for checking them. That order is below, written so you can work through it yourself in about 15 minutes.
What an SSH Broken Pipe Actually Means
Nothing on your server is broken. "Broken pipe" is the operating system telling you that your SSH client tried to write to a network connection that had already been closed underneath it.
Your session is a TCP connection passing through your router, maybe a VPN or corporate firewall, the data centre network and finally the server. Most of those hops keep a table of active connections and quietly delete entries that haven't carried a packet for a while. Type a key after that and your packets go nowhere.
A broken pipe error in SSH means the client wrote to a TCP connection that was already closed somewhere along the path. On most networks the cause is idle time: plenty of NAT routers and firewalls drop a silent connection after roughly 5 minutes, while Linux's own TCP keepalive doesn't fire until 2 hours of silence, so nothing protects the session in between.
You'll see the same problem under different wording depending on your client version:
client_loop: send disconnect: Broken pipe(current OpenSSH clients)packet_write_wait: Connection to 203.0.113.10 port 22: Broken pipeWrite failed: Broken pipe(older clients)
Is my server down when SSH says broken pipe?
Almost never. Try reconnecting straight away. If you get a login prompt within a few seconds, the server was fine and only the idle connection died. If the reconnect hangs or is refused, that's a different problem, and the causes below (a crashed sshd, a firewall block) are where to look.
Why Your SSH Session Keeps Disconnecting: Causes Ranked
Idle timeouts cause most of these drops, and they're the easiest to fix. According to Hostaccent's support queue, which handles 20-30 client issues a day, dropped sessions trace back to the same short list, and an idle timeout somewhere between the user and the server accounts for the large majority of them.
Here's the list in the order we see it:
- An idle timeout on the network path. Home routers, office firewalls, mobile hotspots and cloud NAT gateways all expire quiet connections, typically somewhere between 60 seconds and 15 minutes. This is the classic broken pipe after inactivity.
- A server-side idle rule. A low
ClientAliveCountMax, aChannelTimeoutorUnusedConnectionTimeoutsetting (both added in OpenSSH 9.2, per the official release notes), or aTMOUTshell variable left behind by a hardening script. - The network itself changed. Your laptop slept, you moved from Wi-Fi to 4G, or your VPN reconnected with a new IP address. No setting can save that TCP connection.
- The server side died. sshd killed when the box ran out of memory (see why a VPS runs out of RAM), a reboot, or a firewall such as CSF or Fail2ban blocking your IP mid-session.
- A packet-marking quirk. Some routers and virtual NAT layers mishandle the QoS marks SSH puts on its packets, so the session drops seconds after login. This one is rare but very specific.
Drops after a stretch of silence point to cause 1 or 2. Drops while you're typing or right after login point to cause 4 or 5.
The Three-Hop Fix: Client, Network, Server
Fix the client first, because that single change cures most cases in under 2 minutes. Then add the server side so every person who logs in is covered. Our team calls this order the Three-Hop Keepalive Check: your machine, the path in between, then the server.
Step 1: Turn on keepalives on your computer
Open (or create) ~/.ssh/config on the machine you connect from and add this at the bottom:
bashHost * ServerAliveInterval 60 ServerAliveCountMax 3
Then lock the file down with chmod 600 ~/.ssh/config. On Windows 10 and 11, the built-in OpenSSH client reads C:\Users\<you>\.ssh\config. In PuTTY, go to Connection and set "Seconds between keepalives" to 60, then save the session.
ServerAliveInterval makes the client send a tiny encrypted "are you there?" message after 60 seconds of silence. With a count of 3, a genuinely dead connection is dropped after 180 seconds instead of freezing your terminal forever. The full option list lives in the OpenSSH ssh_config manual.
Pro Tip:
ssh_configuses the first value it finds for each option. If you putHost *at the top, its settings beat every specific host block below it. KeepHost *as the last block in the file and per-server overrides will work the way you expect.
Step 2: Turn on keepalives on the server
This covers every user, even ones who never touch their own config. Create a drop-in file:
bashsudo nano /etc/ssh/sshd_config.d/01-keepalive.conf
Add:
bashClientAliveInterval 60 ClientAliveCountMax 3 TCPKeepAlive yes
Check the syntax with sudo sshd -t (no output means it's valid), then reload. On Ubuntu and Debian that's sudo systemctl reload ssh; on AlmaLinux, Rocky and RHEL it's sudo systemctl reload sshd. A reload doesn't cut existing sessions, but keep your current one open and test from a second terminal before you log out.
The 01- prefix matters. sshd also takes the first value it reads, and on Ubuntu the drop-in folder is read in alphabetical order before the main file, so a cloud image's 50-cloud-init.conf would lose to yours rather than the other way round. While you're in there, hunt for anything that closes sessions on purpose:
bashsudo grep -riE "timeout|clientalive" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ grep -r TMOUT /etc/profile /etc/profile.d/ ~/.bashrc
The sshd_config manual explains every one of those directives.
Live site and no time to experiment? Our engineers can sort out this exact disconnect problem for a small one-time fee, and you'll see the exact quote before we touch anything. Hosted with Hostaccent? Then issues like this are simply covered by support, free. Have an engineer fix it
Step 3: Find the firewall or NAT box in the middle
If both ends send keepalives and you still drop, time the disconnects. Drops at a fixed interval under 60 seconds mean an aggressive firewall sits on the path, common on corporate and hotel networks. Lower both intervals to 25 or 30 seconds and test again, or ask the network admin what TCP idle timeout applies to port 22.
Step 4: Drops right after login? Change the QoS marking
If the session dies within seconds of connecting, even while you type, add this under your Host * block:
bashIPQoS throughput
It changes the priority marks on SSH packets to a value that the problem routers and virtual NAT layers pass through without fuss.
Still working through this server issue?
Send the symptoms, error output, and what you have already tried. We can work with Hostaccent services or infrastructure hosted with another provider.
Keep Long Jobs Running Through Any Disconnect
Keepalives keep an idle connection open, but they can't revive one whose IP address changed. For anything that takes more than a few minutes (a database import, an rsync, a system upgrade), run it inside a terminal multiplexer so the job lives on the server, not in your connection.
bashtmux new -s deploy # start a named session # run your long command, then press Ctrl+b, then d to detach tmux attach -t deploy # reconnect later, even from another machine
screen works the same way if that's what your server has. For laptops that roam between networks all day, mosh survives IP changes, though it needs UDP ports 60000-61000 open in the server firewall.
Across the 4,000+ sites Hostaccent has migrated since 2016, the step most often wrecked by a dropped session is the large database import, so our team runs every migration inside tmux by default. The database side has its own version of this idle-timeout failure, covered in MySQL Server Has Gone Away.
Pro Tip: Running
do-release-upgradeover SSH? Ubuntu starts a backup sshd on port 1022 for exactly this reason. Open that port temporarily, start the upgrade inside tmux anyway, and a dropped link becomes an annoyance rather than a half-upgraded server.
How to Confirm the Fix Worked and Stop It Coming Back
Check that both sides actually loaded your values, then watch one keepalive go out. Two commands answer the first part:
bashssh -G yourserver | grep -i serveralive # client: expect serveraliveinterval 60 sudo sshd -T | grep -i clientalive # server: expect clientaliveinterval 60
For the live test, connect with ssh -vvv user@yourserver and leave the terminal untouched for 3 minutes. You should see a debug3: send packet: type 80 line roughly every 60 seconds. That's the keepalive request defined as a global request in the SSH Connection Protocol (RFC 4254). If the session still dies, check the server log with sudo journalctl -u ssh --since "1 hour ago". A line reading "Timeout, client not responding" means the server closed it; no line at all points back at the network.
A working SSH session timeout fix should survive 30 minutes of idle time with no drop. If yours passes that, bake the client block into your dotfiles and the server drop-in into your new-server checklist so every fresh VPS gets it on day one.
Don't overcorrect by setting ClientAliveCountMax to something huge. Dead sessions then sit on the server holding processes, and on shared plans they count against your limits (the pattern behind shared hosting resource limit exceeded errors). Proxies run their own idle timers too, which is how a stalled backend becomes a 502 Bad Gateway in Nginx. If your server sits on another continent, a closer location such as Amsterdam VPS hosting for EU users means fewer lossy hops.
The short version:
- Set
ServerAliveInterval 60on every machine you connect from. - Set
ClientAliveInterval 60on every server you run, in a01-drop-in file. - Drop the interval to 25-30 seconds on networks with aggressive firewalls.
- Run anything longer than a few minutes inside tmux.
Your Next Step: A Server Where This Is Support's Job
Fixed it? Then the one habit worth keeping is the client-side Host * block, because it prevents an ssh broken pipe on every server you'll ever log in to.
You can keep tuning sshd, firewalls and memory limits yourself, or run your projects on a VPS where engineers already watch that layer. Hostaccent's Standard VPS plan at $12.00/mo gives you full root access on NVMe storage, free 30 Gbps DDoS protection and 24/7 support from our own in-house engineers, and it renews at the same $12.00/mo. One honest caveat: if you run a single small site and never open a terminal, shared hosting will serve you better for less.
Still stuck? Open a ticket with our engineers, and you'll get a quote for the small one-time fee before any work starts.
Frequently Asked Questions
What causes an SSH broken pipe error?
The usual cause is an idle connection being dropped by something between you and the server. Home routers, office firewalls and NAT gateways delete connection records that carry no traffic, often after about 5 minutes. When you next type, your client writes into a connection that no longer exists and reports the broken pipe. Less common causes are a server-side idle setting, a changed IP address after sleep or a VPN reconnect, or sshd being stopped on the server.
What is a good ServerAliveInterval value?
Sixty seconds suits almost every network. It's frequent enough to beat most router and firewall idle timers, yet adds only a few bytes of traffic per minute. Pair it with ServerAliveCountMax 3, so a truly dead link is detected after about 180 seconds. If you're on a network with an unusually aggressive firewall, such as some hotel or corporate setups, drop it to 25 or 30 seconds. Values under 10 seconds rarely help and just add noise.
Should I use ServerAliveInterval or ClientAliveInterval?
Use both if you can. ServerAliveInterval lives in the client config on your own computer and protects you on any server you connect to, including ones you don't control. ClientAliveInterval lives in sshd_config on the server and protects every user who logs in, even those who never touch their local settings. If you can only change one, set the client side first, because it fixes the problem wherever you work from.
Why does SSH still disconnect after setting keepalives?
Either the setting isn't being applied or the drop isn't an idle timeout. Run ssh -G yourserver and sudo sshd -T to confirm the values actually loaded, since an earlier Host * block or another drop-in file can override yours. If they're correct, check whether your IP changed after sleep or a Wi-Fi switch, look in the server log for out-of-memory kills, and confirm no firewall such as Fail2ban blocked your address mid-session.
Does TCPKeepAlive stop broken pipe errors?
Not on its own. TCPKeepAlive uses the operating system's TCP keepalive, which on Linux waits 2 hours of silence before sending its first probe, long after most routers have forgotten your connection. It also isn't encrypted, so it can be spoofed. Leave it set to yes, because it helps clean up dead connections on the server, but rely on ServerAliveInterval and ClientAliveInterval for keeping sessions alive. Those travel inside the encrypted SSH channel and fire as often as you choose.












Discussion
Have a question or tip about this topic? Share it below — your comment will appear after review.