rescueshell Start trial

SSH "channel open failed: connect failed" on a forward

This line comes after the SSH connection was made and a forward was in use. The forward started, you or a program used it, and the connect to the host and port it was aimed at failed. The session itself may still be up. The line tells you that a connect failed, so the next checks are about the target of the forward.

This page describes standard OpenSSH behaviour. The commands are the usual ones, and wording differs between versions and platforms. We did not run them against a particular server or network for this page.

What the line looks like

channel 2: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection reset by peer
channel 2: open failed: connect failed: No route to host

The form is channel N: open failed: REASON, with a message after the reason when there is one. The number is only an identifier for that one connection through the forward, and it will differ from the example. Here the reason is connect failed. The words after it are a system reason for that connect. Connection refused is a usual one, and the others above are examples too. The words can differ between platforms and versions, so do not rely on one exact phrase.

The line can appear many times in one session. Each use of the forward opens a new channel, and each one can succeed or fail on its own. The ssh session can stay open and keep working while one use of a forward fails.

Which page is this?

Several messages sound alike, so check what else the log shows. This page is for a connect that failed after the SSH session was made and a forward was in use.

1. Note which forward was in use

Look at the command you ran for -L, -R and -D, and at the config for the host, for LocalForward, RemoteForward and DynamicForward lines. Then find what was using the forward when the line appeared: a browser, a database client, a script or another program. A dynamic forward takes its target from each request, so for that one, look at what the program asked for.

To see the line in context, run the command again with -v and keep the whole output. The ssh -v output reader can check a pasted log for this line. It runs in your browser and sends nothing.

2. Read the host and the port the forward was aimed at

In a local forward written like the one below, the host and port after the local port are the target:

ssh -N -L 18080:localhost:80 user@server.example.com

Here the target is localhost on port 80. As the local forward page says, that is the host and port as seen from the server, so localhost means the server itself and not your machine. A remote or dynamic forward names its target in its own way. Which end makes the connect depends on the kind of forward, so read the target as the machine that makes the connect would, not as you would from where you are typing.

A typo in the port, a service that moved to another port, or localhost meaning a different machine than you thought are common and cheap to rule out first.

3. Check whether anything listens there

A connect fails when nothing accepts it at that address, so check on the machine that would make the connect. These are generic checks and the exact commands vary by system. Put the real port in place of 80.

ss -ltn | grep ':80'

On Linux, ss lists listening TCP ports. You can also try a connect by hand, if nc is installed, although its options differ between versions:

nc -zv localhost 80

4. Is it every time or only sometimes?

A target that fails on every use points to the address, the port or a service that is not running. A target that fails now and then, or only under load, is a different clue, for example a service that restarts or a limit on the target. Note when it happens, and look at the log of the service the forward is aimed at, if you can.

A forward that failed to set up is a different matter. The option ExitOnForwardFailure, covered on the local forward page, is about a forward that could not start. It is not what this line is about, since here the forward did start and a single connect through it failed.

If the machine is a RescueShell device

A path that starts from the device can avoid depending on an inbound SSH port or on a forward you hold open yourself. The agent on the device keeps an outbound HTTPS connection to our relay, so reaching a shell does not depend on an open port on the device. See SSH behind a firewall without port forwarding. That needs the agent installed and running first.

This line is about a forwarded target that did not accept a connect. The relay does not make a service on the far side start listening. If you need a web page or a database that is not running, it still has to be started on the machine that hosts it. 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.