Skip to content
Log In Sign Up info@muvcloud.com

What the Message Means

A broken pipe is the operating system telling a program that the other end of a connection has closed. In SSH it appears as:

client_loop: send disconnect: Broken pipe

Older clients show a similar line starting with packet_write_wait. Either way, the TCP connection was dropped somewhere, and the client finds out only when you press a key.

Why Idle Sessions Drop

  • NAT and firewall timeouts: home routers, office firewalls, and mobile networks keep a table of open connections and remove entries that have been quiet for a while, often a few minutes. The next packet then has nowhere to go.
  • Your computer slept: a laptop that suspends or changes networks breaks every open connection.
  • The server went away: a reboot, the SSH service restarting, or the server running out of memory ends the session too.

Only the first case is fixed with keepalives. If sessions drop while you are typing, look at the network instead; SSH connection timed out covers the checks.

Fix It on Your Computer

The client can send a small encrypted keepalive message when the connection is idle. Add these lines to ~/.ssh/config on your own computer:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

ServerAliveInterval is the number of idle seconds after which the client sends a message. ServerAliveCountMax is how many unanswered messages it allows before it closes the session itself, so a dead connection is noticed after about three minutes instead of hanging. Instead of Host * you can set it for one server only; the file is explained in the SSH config file. To try it for one connection:

ssh -o ServerAliveInterval=60 user@your_server_ip

This is the preferred fix: it works for every server you connect to and needs no change on the server.

Fix It on the Server

The server can send keepalives as well, which helps every client, including ones you do not control. Keep your current SSH session open while you do this. Create a drop-in file:

sudo nano /etc/ssh/sshd_config.d/10-keepalive.conf
ClientAliveInterval 60
ClientAliveCountMax 3

ClientAliveInterval and ClientAliveCountMax work like the client settings, in the other direction. sshd uses the first value it finds for each setting, and the drop-in files are read in name order, so a low number at the start of the name keeps another file from overriding yours.

Test and Reload the SSH Service

Current releases of Ubuntu, Debian, AlmaLinux, and Rocky Linux read files in sshd_config.d; if yours does not, add the lines to /etc/ssh/sshd_config. Test the configuration, and reload only if the test prints nothing:

sudo sshd -t

On Ubuntu and Debian run sudo systemctl reload ssh; on AlmaLinux and Rocky Linux run sudo systemctl reload sshd. Then open a second session to confirm you can still log in before you close the first. More on this step is in how to restart the SSH service.

Keep Work Running Through a Drop

Keepalives do not help when your laptop sleeps or the network changes. A long upgrade or database import started in a plain SSH session stops when the session ends. Run it inside tmux instead:

tmux new -s work

If the connection drops, log in again and reattach:

tmux attach -t work

The commands kept running on the server the whole time. The keys you need are in the tmux cheat sheet. For a single command that should outlive the session, nohup also works.

Settings That Do Not Help

  • TCPKeepAlive: on by default on both sides, but its probes are sent only after a long idle time set by the operating system, usually far longer than a router's timeout.
  • Very short intervals: a few seconds adds traffic without benefit; 30 to 60 seconds is enough for most networks.
  • Raising the count very high: makes the client wait longer on a connection that is already dead.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations