Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

SSH session dies with client_loop: send disconnect: Broken pipe

Errorclient_loop: send disconnect: Broken pipe

Short 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.

  • Applies to OpenSSH 9.x, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Reconnect with verbose output and watch what the client logs just before it drops.

    ssh -vv user@example.com
  2. 2Match what you see, then jump to its fix

    1. 1The drop happens after a quiet stretch while the experiment runs without outputThe client sends no keepalive messagesFix
    2. 2You administer the server, and the client config is already rightThe server drops the client for not answeringFix

What does the error look like?

  • client_loop: send disconnect: Broken pipe
  • Broken 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 3

3Verify

Reconnect and leave the session idle for longer than it used to survive.

ssh -v user@example.com 2>&1 | head -n 40

Confirmed by man.openbsd.org

Did this fix it?

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 3

3Verify

Read the values back, reload sshd, then repeat the long run.

grep -ri clientalive /etc/ssh/sshd_config

Confirmed by man.openbsd.org

Did this fix it?

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.