Hi everyone!
I am trying to set up a reverse ssh tunnel from a windows machine using Cygwin (openssh) , to a Linux server machine with static ip, so i can access the windows pc directly through the server from any other machine.
My ultimate goal is to be able to connect through remote desktop (rdp) to the windows pc from any other pc through the ubuntu server.

I managed to take the first step which is setup a ssh server in cygwin and to open a reverse ssh tunnel from windows pc to the server using the following command in cygwin :

ssh -nNT -R server-ip:5000:localhost:22 username@server-ip

So with tunnel running i can connect from any other pc to the windows pc with the following two steps:
1) connect to the linux server

ssh username@server-ip

2) connect to the windows pc using the tunnel created earlier

ssh username@localhost -p 5000

My first question is this :
Why can't i use directly the following command from any PC to connect directly to the tunnel:

ssh username@server-ip -p 5000
ssh: connect to host server-ip port 5000: Connection refused

Is there anyway to set this up?

Secondly, if i manage to do this, is there a way to forward rdp port so i can connect directly from any pc to the windows client using remote desktop protocol?
Using something like :

ssh -L 3390:localhost:3389 username@server-ip

Thanks in advance.

Recommended Answers

All 4 Replies

I found the answer to my first question.
I changed the first code line to :

ssh -nNT -R :5000:localhost:22 username@server-ip

The empty ip before :5000 indicates that a connection can be established from any external ip.

and added this line in my linux server's sshd_config file which enables port 5000 to be a gateway for incoming connections

GatewayPorts yes

And now i am able to connect to the windows pc using the following command from any computer with internet access :

ssh username@server-ip -p 5000

Now the second question remains unanswered. I read a lot of guides and i am pretty confused.
Is there anyway i can forward the rdp port (3389) to the ssh tunnel so i can connect from any pc?

I think it is possible but i can't figure out how to do it.

Another possible approach may be to install the Windows Services For Unix, which as I recall includes an ssh server component. That may be better than trying to tunnel via Cygwin.

I've been working with Cygwin for years now, and i may say that it is one of the most robust "applications" i've ever seen. The ssh server of Cygwin is the last service that i would expect to crash, even if all of the operating system is unresponsive.

In addition to that, i don't think that there will be any difference since both of them just implement the ssh server which is quite the same in all the platforms i ever used it.

Looks like i 've misunderstood the whole idea here.
I had the answer in front of my eyes from the beginning :

ssh -nNT -R :5000:localhost:3389 username@server-ip

I simply changed port 22 to 3389, which is the rdp server port..

I thought that the ssh tunnel was supposed to work between two ssh servers and then i would be able to forward any ports someway. But the truth is that you can directly forward any port since the tunnel is ready.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.