Skip to content
SSH10 min read14.08.2026

Why Does SSH Disconnect? Broken Pipe and Keepalive Guide

An SSH session that drops after a few minutes may be caused by a mobile network change, NAT timeout, server policy or a connection that carries no traffic for too long.

Broken pipeKeepaliveConnection resetSSH timeout
SSH terminal session in Varkuna Connect

What does the disconnect message tell you?

Broken pipe

The client can no longer write to the peer; the underlying network path may have failed earlier.

Connection reset by peer

The remote system or an intermediate network device may have reset the TCP connection.

Connection timed out

No response arrived within the expected time because of the route, firewall or unavailable server.

Connection closed

The server may have ended the session because of policy, maintenance, resource limits or a normal logout.

Common reasons an SSH session drops

When a phone moves between Wi-Fi and mobile data, the address associated with its TCP connection can change. The operating system may also restrict background network activity after the screen turns off. Routers, firewalls and corporate NAT devices can delete idle flows from their tables.

On the server, ClientAliveInterval, idle-shell policy, account limits or maintenance can end the session. Determine whether the failure happens after a consistent interval, only during a network change or while large amounts of output are moving.

ServerAliveInterval vs TCPKeepAlive

SettingHow it worksPurpose
ServerAliveIntervalRequests a response through the encrypted SSH channelDetects an unresponsive peer and may keep an idle NAT flow active
ServerAliveCountMaxLimits unanswered server-alive messagesControls when the connection is considered failed
TCPKeepAliveUses operating-system TCP keepalive messagesCan detect a dead path but is separate from the SSH-level mechanism
Example for one connection
ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3 user@server

Step-by-step diagnosis

  1. 1
    Measure the interval

    A repeatable failure after the same number of minutes points toward an idle policy or NAT timeout.

  2. 2
    Check network changes

    Test the relationship with Wi-Fi signal, VPN reconnects, mobile-data switching and device sleep.

  3. 3
    Collect verbose client output

    With OpenSSH, use -v and if needed -vv or -vvv to see when the session closes.

  4. 4
    Inspect server logs

    Look for sshd shutdown, account policy, resource limits or a server restart at the same time.

  5. 5
    Test a measured keepalive

    Use a reasonable interval and compare whether the problem is specifically an idle-flow timeout.

Considerations for phones and laptops

Battery optimization

The operating system may suspend the app or network when the screen is off.

Network handover

An active SSH TCP session normally cannot move seamlessly to a different public address.

VPN reconnect

Rebuilding a VPN tunnel can invalidate the existing SSH flow.

Long-running jobs

Use a server-side session manager such as tmux or screen when work must survive a client disconnect.

Do not overuse keepalive settings

Very short intervals add unnecessary traffic and battery use. Keepalives do not repair poor Wi-Fi, a stopped SSH service or a restarted server; they only test the connection more regularly.

Before changing a server-wide policy, consider its effect on other users and automation. A client-specific setting is a controlled way to test one user’s idle-session problem.

Do not tie critical work to one terminal

For a job that must run for hours, use a reconnectable server session or service instead of relying only on an open mobile connection.

Continue

Put the guide into practice.

Review the related Varkuna product or open its detailed user guide.