DEV Community

Cover image for RDP via SSH (PuTTY)
Adam K Dean
Adam K Dean

Posted on

RDP via SSH (PuTTY)

If you're like me, and you're paranoid about opening up access to your servers to the internet, you might sometimes find yourself needing to access them but not being on the local network. A handy trick to circumvent this, if you have access to SSH, is to open a tunnel.

For this we're going to need:

  • The IP or hostname and port of the destination server (for this they are 192.168.1.2 and 3389)
  • Access to a server with SSH on the local network
  • PuTTY on your local machine

First, open up either command prompt, or MinGW or something, and navigate to your PuTTY path:

cd /c/PuTTY/
Enter fullscreen mode Exit fullscreen mode

Then connect to the SSH server specifying a tunnel like so:

putty.exe -L <localport>:<remotehost>:<remoteport> <sshserver>
Enter fullscreen mode Exit fullscreen mode

For example:

putty.exe -L 8001:192.168.1.2:3389 adamkdean.co.uk
Enter fullscreen mode Exit fullscreen mode

This will open up a PuTTY window. Authenticate and open up another cmd/mingw prompt. In this one we're now going to use mstsc (remote desktop) to connect through the tunnel. We opened up port 8001 on our local machine, so lets connect to that.

mstsc -v localhost:8001
Enter fullscreen mode Exit fullscreen mode

If you've done everything right, you should now get a remote desktop prompt.

Update from 11/02/2016: You can tunnel connections with regular ssh like so:

ssh user@hostname -L <localport>:<host>:<remoteport> -N
Enter fullscreen mode Exit fullscreen mode

-L is for your tunnel, and -N is no command executed on connect.

Latest comments (0)