I’d been having some annoyances with RDP (Remote Desktop) over SSH. The primary source of annoyance stemmed from the Win2k/XP client not allowing you to connect to your local IP regardless of port, forwarded or otherwise. Luckily, it isn’t actually clever enough to know that the 127.0.0.2 address is also tied to the loopback device (one of Microsoft’s little liberties that turns out to actually be handy - who knew?!). So, here’s a solution that’ll save you time struggling and cash from buying an application such as WiSSH that is entirely unnecessary.
You’ll need to go and get plink.exe from PuTTY, but that’s about it.
To open the tunnel, run the following:
plink.exe -ssh -2 -batch -v -L 127.0.0.2:<any available local port to listen on>:<IP address of machine running RDP behind SSH server>:3389 -pw <password> -P <port SSH is listening on [default is 22] > <user>@<SSH server IP address or hostname> “sleep 30″NOTE: The first time you run this, do not include the “-batch” parameter or the “sleep 30″ command on the end because you have to manually accept the SSH server’s key so it gets added to your Windows registry for future use, and then type “exit” to disconnect.
For example, the command looks like this for me:
plink.exe -ssh -2 -batch -v -L 127.0.0.2:3390:192.168.0.100:3389 -pw feedmepie -P 2222 wibbles@volved.com “sleep 30″"sleep 30" is required (including quotes) as this keeps the channel open for 30 seconds, which should be long enough for you to open your RDP connection with 127.0.0.2:3390 as the server address.
Use the following command to open your RDP connection from a batch file, or the Start->Run dialog (the parameters in bold are for screen Width and Height, and obviously optional):
mstsc.exe /v:127.0.0.2:3390 /w:1280 /h:1024Here’s a screenshot of what the plink.exe command looks like. On the last line, it’s indicating that it has just run the sleep 30 command and then it sits waiting for the open port forwarding to be used:

To simplify all of this, I cleaned-up a VBS script I found that prompts for all of the parameters in turn so you don’t have to keep them saved in an insecure batch file or anything. Grab a copy of rdp_connect.vbs and put it in the same directory as plink.exe and after connecting, it’ll automatically run the RDP client and attempt to connect for you. To create a shortcut to this script, you’ll want to prefix it with the wscript command as simply double-clicking a .vbs file does nothing but open a text editor (not entirely helpful really).
1 Response to “RDP over SSH”