1

I have done basically two identical ssh -R forwards, but only one works. Here is my situation:

At work: server/computer that I want to log in to remotely

At home: Desktop Laptop

Router forwards: Port 22 and 49666 to Laptop Port 49667 and 49668 to Desktop

the IT department at work wants me to use ssh -R on the computer there instead of them opening a port normally for some reason (I guess they are worried about security if they leave a port open). It was a big concession for them to allow me to do this and I don't want to have to argue with them more over opening a port normally. So I do this at work

ssh -R 49666:localhost:22 (home IP) -N   #this is for the laptop

Then, on my laptop, I can do:

ssh localhost -p 49666

and I get in to the work computer successfully.

At work, I also do:

ssh -R 49668:localhost:49667 (home IP) -N   #this is for the desktop

However, on my desktop, if I try

ssh localhost -p 49667

I get:

ssh: connect to host localhost port 49668: Connection refused

The commands are basically analogous, so I'm not sure why one works and the other doesn't. My first thought was that since the default ssh port is 22, then my desktop is not listening to 49667. So I went in /etc/ssh/sshd_config and changed it to listen to 49667, but I still get the same error.

If I am at the work computer and I type:

ssh (home IP) -p 22

I successfully log in to the laptop. Similarly if I type

ssh (home IP) -p 49667

I successfully log in to the desktop. So I don't think it's a security issue on my desktop, since I can get into it from the work server.

My second thought was that, in the ssh -R command, the (home IP) part is trying to go to port 22 at home IP, because the work computer has ssh on default port 22 and it doesn't know that I set the destination computer to look at port 49667 instead. So my next try was this

I went into ~/.ssh/config on the work computer and put in a line like this:

host Desktop 
hostname (home ip)
port 49667

Now, if I go on the work computer and type

ssh Desktop

it successfully logs on to the Desktop, as it's basically the same as the command above:

ssh (home IP) -p 49667

So, I try doing this ssh -R line on the work computer:

ssh -R 49668:localhost:49667 Desktop -N

Now when I try to ssh in to the server from the desktop at home, I get this error:

ssh_exchange_identification: Connection closed by remote host

Which is different then the failure I got before (the connection refused one, which I think just means there was no port forwarding at all). Additionally when I get the above failure, this failure pops up on the work server (I know becuase I am watching it from my laptop)

connect_to localhost port 49667: failed.

So I am getting some different reaction in this case, but still no success. And I am out of ideas...

All 3 computers (work, laptop, desktop) have correct public keys for each computer.

iammax
  • 348

1 Answers1

1

I guess I have the awkward luck to figure out my answer 15 minutes after posting the question, so I'll post my solution in case somebody else has a similar issue... The following command worked for me

ssh -R 49668:localhost:22 Desktop -N

For some reason I thought the second port number (22 in this case) was supposed to be the port where the target computer (the IP which is in the config file under "Desktop") listens to ssh. But this worked, so I was wrong. Perhaps it is supposed to be the port where ssh is listened for in the computer where the ssh -R command is executed?

iammax
  • 348