SSH "remote port forwarding failed for listen port"
This line comes after the SSH connection was made and you asked for a remote
forward, with -R or a RemoteForward line. It means
the far side did not start listening on that port or path. The session itself
may still be up, now without that 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
Error: remote port forwarding failed for listen port 2222
Warning: remote port forwarding failed for listen port 2222
The same two forms exist with listen path in place of
listen port, for a forward that listens on a socket path. The
port or path in these examples is only an example, and yours will differ. We
are not sure when ssh prints the Error form and when it prints
the Warning form, so this page does not rely on the difference.
Read the port or path in the line either way.
A remote forward asks the server side to listen, so the failure is about the far machine, not yours. The line says the listen did not come up. It does not say why.
Which page is this?
Several messages sound alike, so check what else the log shows. This page is for a remote listen that did not start.
- Address already in use on a local forward means ssh could not listen on a port on your own machine. Here the listen that failed was requested of the far side.
- channel N: open failed: connect failed means a forward was listening and one connect to its target failed later. In this case the listen itself did not come up.
- The autossh guide is about a persistent tunnel that keeps dropping. It uses this line as one reason such a tunnel can look healthy with no forward behind it. This page is the everyday line on its own.
-
A line that says a channel was
administratively prohibitedis a different message, about a forward the server refused to open after the tunnel was up. This page does not cover it.
1. Read the port or path in the line and in your command
Compare the port or path in the line with what you asked for. Look at the
-R option in the command and at any RemoteForward
line in the config for that host:
ssh -N -R 2222:localhost:22 user@server.example.com
In a remote forward written like this, the first number is where the far side
was asked to listen, and the host and port after it are where connections come
back to. A typo in the port, or a config entry that supplies a port you did
not expect, is cheap to rule out first. 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. See whether something already listens there
A listen can fail when something else already holds the port or path on the far side. These are generic checks and the exact commands vary by system. Run them on the far machine, and put the real port in place of 2222.
ss -ltn | grep ':2222'
On Linux, ss lists listening TCP ports. If something is there,
find out what it is. It may be another program, or the same forward requested
twice. It may also be an older ssh session that the server has not yet closed,
for example after a link that dropped without telling anyone. The
autossh guide describes
that case. If nothing is listening and the port or path is right, the line
alone does not say what else prevented the listen, and the server side may
have its own reasons.
3. Decide whether the session should carry on without it
Because the session can stay up with no forward behind it, a script or a
supervisor may think everything is fine. The
local forward page covers
the ExitOnForwardFailure option, which makes ssh end the
connection when a forward cannot start. The
autossh page says the
same about a tunnel that stays connected unless you tell ssh the failed
forward is fatal. Check those pages for the option instead of copying a recipe
from here.
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 remote listen that did not come up. The relay does not make a port start listening on someone else's server. 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.