SSH session dies with client_loop: send disconnect: Broken pipe
client_loop: send disconnect: Broken pipeShort answer
By default neither ssh nor sshd sends keepalive messages through the encrypted channel (both intervals default to 0), so a quiet session gives nothing for a firewall or the server to see. Set ServerAliveInterval on the client, and ClientAliveInterval on the server if you control it.
Fix it fast
1Find out which cause you have
Reconnect with verbose output and watch what the client logs just before it drops.
ssh -vv user@example.com2Match what you see, then jump to its fix
What does the error look like?
client_loop: send disconnect: Broken pipeBroken pipe
Cause 1 of 2
The client sends no keepalive messages
1Check
ServerAliveInterval defaults to 0, so ssh never sends a message through the encrypted channel to request a response. Read what is set now.
grep -ri serveralive ~/.ssh/config /etc/ssh/ssh_config /etc/ssh/ssh_config.d/2Fix
Ask for a response every 30 seconds in ~/.ssh/config. ssh disconnects only after ServerAliveCountMax (default 3) unanswered messages.
Host *
ServerAliveInterval 30
ServerAliveCountMax 33Verify
Reconnect and leave the session idle for longer than it used to survive.
ssh -v user@example.com 2>&1 | head -n 40Confirmed by man.openbsd.org
Cause 2 of 2
The server drops the client for not answering
1Check
ClientAliveInterval on the server also defaults to 0 (no messages). If it is set, the server ends the session after ClientAliveCountMax unanswered messages.
grep -ri clientalive /etc/ssh/sshd_config /etc/ssh/sshd_config.d/2Fix
Set an interval and a tolerant count in sshd_config, then reload the sshd service.
# /etc/ssh/sshd_config
ClientAliveInterval 60
ClientAliveCountMax 33Verify
Read the values back, reload sshd, then repeat the long run.
grep -ri clientalive /etc/ssh/sshd_configConfirmed by man.openbsd.org
How do I stop it coming back?
- Put ServerAliveInterval in ~/.ssh/config once, for every host.
- Keep a second ssh session open while you change sshd_config, so a typo cannot lock you out.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix