rescueshell Start trial

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:

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.

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.

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.