ssh tunneling to a terminal services

Posted on 2003-12-11
Last Modified: 2013-11-15

I've been trying to ssh tunnel to connect to a machine via terminal services without success.

This is my setup,

From home i'm able to ssh tunnel to a machine at my work network and forward port 80 to my machine at home with no problem.  But now i need to do this for terminal services.

I use cygwin to ssh to a linux server in my network then when i try to forward port 3389 to the terminal service machine and it fails.

on the Linux server i use the following command   ssh -L 3389:localhost:3389  user@linuxserver

Another thing is also that i would have to somehow use a gui so that i can launch the terminal services screen so i've compiled cygwin with xfree86.

Basically i just want to get some suggestions on what would be the correct path for me to do this.


Question by:m3m0
  • 3
  • 2
  • 2
  • +2
LVL 40

Expert Comment

ID: 9920564
Whew!  You might want to put this into the Linux area if you don't get help here.  Certainly out of my boundary.  Just a thought in case you don't get help, but there are some real good experts here who might join in.


Author Comment

ID: 9920660
Great thank you.
LVL 38

Expert Comment

ID: 9925434
"i would have to somehow use a gui so that i can launch the terminal services screen so i've compiled cygwin with xfree86."

All you need to do is to enable X forward at both client and server for your secure

have a look at the following pages about how:

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

LVL 40

Expert Comment

ID: 9925592
That is what we needed, a Unix Master!  :)


Accepted Solution

marko020397 earned 125 total points
ID: 9926394
I am using this ssh tunneling for a long time now for terminal services and it works great.

You are not specific in your question how exactly you would like to connect. Let's
asume you are running ssh on some Windows machine in network "one". You want
to connect to another Windows machin in network "two" where you also have a Linux

1. I think the ssh command you are using is wrong. It should be:
   ssh -L 3386:win_server_on_nwetork_two:3389  user@linuxserver
  That way you are connecting to Linux server and make a tunnel to Windows machine.
  As you can see I have changed the first port number. We'll get to that later.

2. Now you have the tunnel from your Windows machine on network one to Linux server.
  That tunnel opens (ends) on Linux server and goes on port 3389 to Windows machine.

3. Now you have to run your Terminal Services Client and connect to localhost on port 3386.
   You may have your own Terminal Services Server on the machine you are connecting
   from. If you use 3389 on both sides of ssh it will conflict with the Terminal Server running
   on machine when ssh is running.

Now a few tricks. How can you connect to localhost:3386.

Windows 2000 and older:
You have to set your terminal services connection to connect to localhost. Then save it and
open the saved file with notepad and change the port to 3386.

Windows XP, 2003:
Windows XP and 2003 do not allow connections to localhost. You need to copy two files
from \Windows\System32 directory to another location. The files are mstsc.exe and
mstscax.dll. Open properties for mstsc.exe on new location and set Windows 98 compatibility
mode. Now you can connect to localhost:3386. You don't have to save the connection in
XP and 2003 you can just specify port along with location. (localhost:3386).

I hope this will help you. If you have any more questions just ask.
LVL 38

Expert Comment

ID: 9927936
X tunneling also works between *nix and secure shell client for Windows,
(please remember to enable X11 tunneling in your windows ssh client).

If you setup X tunneling properly, the ssh can automatically setup the DISPLAY
value for you. and you can run you GUI app (including your terminal services,
inside the ssh connetion).
LVL 20

Expert Comment

ID: 9929539
Yes, I think Greg(yuzh) is on to an alternative to markos suggestion here. Instead of going through the hassle of setting up RDP forwarding via the linux box, be sure to install rdesktop on the linux machine, start XWin (at home), ssh -X (to work/linux), rdesktop terminal server....:-)

Slightly cumbersome any way you turn it:-).

-- Glenn
LVL 20

Expert Comment

ID: 9929554
rdesktop homepage:

-- Glenn

Author Comment

ID: 9957673
Damm all you guys Rock!  I wish i could you all points for just looking at my question :-)  

In any case I was more confortable with Markos suggestion which worked.  BUt i''ll try the rest as well.  So I'll be awarding points to Markos.

Again, I aprecieate all the help and comments.


LVL 40

Expert Comment

ID: 9957714
Speaking for everyone here, am glad we could be of service.  BTW:  your company hiring?  :)  Just kidding.

Have a Happy Holiday Season.


Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If your app took Google’s lash recently, here are the 5 most likely reasons.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This video demonstrates basic masking and how to edit the mask to reveal the desired image.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now