SSH "Connection closed by remote host" and "Broken pipe"
These lines come after a connection was made, often after login had started or even finished. Your ssh reached something, and then the session or the path ended. The message says that it ended. It does not say which side ended it or why, so this page is a short order of checks and not a single cause.
This page describes standard OpenSSH behaviour. The commands are the usual ones, and wording can differ between versions and platforms. We did not run them against a particular network or server for this page.
The four lines
Connection closed by 203.0.113.10 port 22
Connection to server.example.com closed by remote host.
Read from remote host server.example.com: Connection reset by peer
client_loop: send disconnect: Broken pipe
They are different wordings of a similar moment, and not four names for one cause. Roughly:
-
Connection closed by ADDRESS port Nsays the other end closed the connection. In newer OpenSSH versions it can show up after login attempts as well as at the end of a session. -
Connection to HOST closed by remote host.is the line an interactive session can end with when the other end closes it. -
Read from remote host HOST: Connection reset by peersays that, while ssh was reading, the connection was reset instead of being closed in an orderly way. Something on the other end or in the path sent a reset. -
client_loop: send disconnect: Broken pipesays ssh tried to send on a connection that was already gone. Older versions word it differently.
Which one you see depends on what ssh was doing when it found out and on the version and platform. Do not read more into the choice of wording than that. Any of them can follow a long quiet period, a network change on your side, a restart or a limit on the far end, or a close made by something in between.
Which page is this?
Check what else the log shows before you work on this page.
A kex_exchange_identification line
means the handshake ended before login started, and that page covers it, even
when a short Connection closed by ADDRESS port N line comes with
it.
A timeout, a refusal, an unreachable network or no route to host
means the connection was never opened. Permission denied, covered in
SSH "Permission denied (publickey)", is a login that was turned down while the connection was still up. A line
such as
channel 2: open failed: connect failed
is about one connect through a forward that failed, and the session may still
be up. This page is for a connection that was made and then ended.
1. Read what ssh shows before the close
Run the command again with -v and keep the whole output:
ssh -v user@server.example.com
Look at what comes just before the closing line. Did login finish, with a prompt or a command running? Did it end at once after the connection opened, or after a long time? A session that ends again and again at about the same point, or after about the same time, is a different clue from one that ended once. The ssh -v output reader checks a pasted log for well-known messages, including these lines, and links the matching guide. It runs in your browser and sends nothing.
2. Was it a one-off, or does it repeat?
A session that ended once, for example after a laptop slept or a Wi-Fi network changed, may need nothing more than a new connection. If it repeats, note whether it happens only from one network, only to one host, or only when the session is idle.
- Does the same host still answer? Open a second connection, or try from another network such as a phone hotspot. If the host answers there, the break was on the path between you and it. If it does not answer at all now, see the timeout guide.
- Did your own network drop? A Wi-Fi change, a VPN that reconnected, a sleeping laptop or a switch to mobile data can end a connection without anything being wrong at the far end. Your own machine's network is worth ruling in or out first.
-
Was it idle? Something in the path, such as a router, a
firewall or a proxy, can drop a connection that has been quiet. This page
does not say how long, because that differs from one device and network to
the next. ssh has a client option,
ServerAliveInterval, that sends a periodic message so a quiet connection is noticed or kept busy. If those messages go unanswered, ssh ends the session itself and printsTimeout, server not responding, which is a different line from the four above. The autossh guide shows how it is used on a persistent tunnel. We do not suggest a value here.
3. Look at the far end, if you can reach it
If you can get a shell some other way, or someone is at the machine, the far side can tell you more than the client does. These are generic possibilities, not a diagnosis.
- Did the machine restart or lose power? A session ends when the machine or its network goes away, and the client may report a close or a reset when it finds out.
-
What does the sshd log say? On many systems
sudo journalctl -u sshshows it, and the service issshdon some distributions. Look at the lines around the time the session ended. A reason, if there is one, is usually written there. - Was it something on the host? A process that was stopped for lack of memory, a service that was restarted, or a change to sshd or a firewall can end sessions. If this started right after a change to a firewall or sshd, see locked out of SSH after a firewall change.
A persistent tunnel is a different problem
This page is about the ordinary client line when one session ends. If the thing that keeps dropping is a reverse tunnel that a device holds open to your own server, the autossh tunnel guide covers keeping it up and restarting it.
If the machine is a RescueShell device
A path that starts from the device can help when you rely on an inbound SSH port that later closes from the internet side. The agent on the device keeps an outbound HTTPS connection to our relay, so a public SSH port or a forward is not part of the path to a shell, and nothing has to be open inbound. See SSH without port forwarding. That needs the agent installed and running first.
It does not fix every close. A session that ended on the machine you typed on, because your own network dropped, is not changed by the relay. A device that has no network of its own cannot reach it, and a session that the device's own SSH server ended still ends there. If a shell does not open once the agent is installed, see the shell does not open.
Try it on one device
The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.