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.