Trying to test a setup for ssh forwarding but keep running into problems.

Here's the setup:

Local machine runs command:

ssh -fNT -v -v -L 8087: user@remotehost

and then remote machine runs:

nc -l -p 8077

and then on the local machine:

nc 8087 < example.txt

What I expect is to see the contents of example.txt but instead I see this error on the remote machine:

 channel 2: open failed: connect failed: Connection refused

From what I understand it throws the error because nothing is listening, but netcat is listening so I'm somewhat confused. My firewall is configured correctly so I'm sure that's not the case.

I'm unsure what is causing this error and any documentation I've found has not adequately explained it.


It ended up working eventually with the same setup. However, I'm still unsure what that error means exactly. To keep the question relevant to others seeking help I am updating it to focus on the error message itself rather than how to configure port forwarding.

  • You're running nc -l on both ends, or is that a typo in your question? – user4556274 Jun 21 at 15:31
  • your -L option seems to be pointing port 8077 on your localhost to port 8077 on your localhost, which won't work. You could change that to -L 8077:remotehost:8077, which may work for you. or if you want to limit access to the local port 8077 to your local machine -L – Tim Kennedy Jun 21 at 15:53
  • Yes the nc -l on both ends is a typo sorry. – shenk Jun 21 at 18:28
  • @TimKennedy not sure what the issue was exactly, but it worked fine when I tried it again with the setup in my question. I've updated the question for others seeking help with this error rather than about how to set up port forwarding as there are plenty of resources on how to do this. I would still like to understand the channel 2 open failed connect failed error. – shenk Jun 21 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.