1

Good day, I'm trying to create a reverse ssh tunnel with my university's remote server. I run the following command on my laptop:

< home >$ ssh -R 9999:localhost:9190 my_user@school_server.edu

I then open another terminal and run

< home >$ nc -l 9190

And on the terminal where I created the tunnel, after logging in, I run

< university >$ nc localhost 9999

When I try this on other computers, I get a connection without a problem between the remote server and the local computer, but on my laptop, I get

< university >$ connect_to localhost port 9190: failed.

When I run the nc command from the remote server.

I have both MacOS as well as Manjaro installed on my laptop, but the problem occurs with both, so it's not a firewall or OS network configuration problem. I've tried using a different network and the problem persists. I have just tried doing the exact same thing with my sister's laptop and it works, and my classmates can do it as well without a problem, so the remote server shouldn't be the problem.

Any idea of what might be causing an issue like this one? Thank you.

EDIT: I forgot to mention, the non-reverse tunnel works perfectly.

More info: Running with the -v flag outputed the following when trying to connect:

debug1: client_input_channel_open: ctype forwarded-tcpip rchan 3 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 9999, originator 127.0.0.1 port 34590
debug1: connect_next: host 127.0.0.1 ([127.0.0.1]:9190) in progress, fd=9
debug1: channel 1: new [127.0.0.1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connection failed: Connection refused
connect_to 127.0.0.1 port 9190: failed.
debug1: channel 1: free: 127.0.0.1, nchannels 2
4
  • 1
    Try running ssh with the "-v" flag to print debugging info: ssh -v -R .... Ssh will print more detail about why the connection to 9190 is failing.
    – Kenster
    Nov 21, 2019 at 16:13
  • 1
    Can mention the host where you run each command. The other terminal is a bit confusing. Maybe something like home:$ command1, unversity:$ command2 Nov 21, 2019 at 16:13
  • sometimes localhost can mean ::1 (ipv6) rather than 127.0.0.1 (ipv4). Can you replace everywhere localhost with 127.0.0.1 and try again?
    – A.B
    Nov 21, 2019 at 17:34
  • I have tried replacing localhost with 127.0.0.1, but get the same results. I updated the post with the verbose output and terminal notation to make it more clear.
    – Bensas
    Nov 22, 2019 at 17:16

2 Answers 2

2

It is an order-of-operations issue. The SSH client is trying to pre-emptively set up the connection to port 9190 of the home computer right after the SSH connection is established, before the remote nc at the university system even starts. If the local port 9190 is not listening at that time, the remote forwarding set-up will fail.

So, you'll have to run your local nc -l 9190 before starting the SSH connection, not after it.

There may be differences between OpenSSH versions in the exact behavior of the remote forwarding: newer versions might delay opening the local extension of the tunnel until something connects to the remote end.

1
  • So, the real order is following: local> nc -l -p 9190 then local> ssh -R 9999:localhost:9190 my_user@school_server.edu then remote> echo "I am here!" | nc localhost 9999 Apr 15, 2021 at 22:39
0

localhost is from the point of view of school_server.edu. So it is trying to connect to 9190 on the remote.

I think you want it to connect to your local. Therefore (and this bit I am not 100% sure about) you should drop the host name. ssh -R 9999:9190 my_user@school_server.edu

3
  • I tried this, but still didn't work
    – Bensas
    Nov 22, 2019 at 17:12
  • What error message? Nov 22, 2019 at 17:13
  • No error message, the command "nc localhost 9999" simply runs and closes immediately, as if I'd inputed any unassigned port.
    – Bensas
    Nov 22, 2019 at 20:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.