Setting up Remote Desktop via SSH Tunnel Print

  • 0

For setting up Remote Desktop to server from monitoring server via SSH tunnel + public key authentication. What you need is:-

  1. monitoring-server-IP (consult tech server)
  2. username & password (consult tech server for the particular server you wish to tunnel and remote into)
  3. tunnel-port-number (check for available port numbers in monitoring server, e.g. via lsof -i -P -n | grep -i listen)
  4. tunnel-monitoring-port-number (same as #3, only choose a different port. See tech server for examples from other servers)

Once you have all the information above, you can start setting up and initiating the tunnel at the server you want to remote into, as follows:-

  1. Download Cygwin (http://www.cygwin.com/)
  2. Install Cygwin, selecting the autossh package.
  3. Start the Cygwin shell (Start -> Programs -> Cygwin).
  4. Generate a public/private key pair.
    1. At the command line, run: ssh-keygen
    2. Accept the default file locations
    3. Use an empty passphrase
  5. Copy your newly-created public key to the SSH server.
    1. scp -vrpP 22222 .ssh/id_rsa.pub username@monitoring-server-IP:.
  6. Add your public key to your list of authorized keys on the monitoring server.
    1. Login to monitoring-server-IP via SSH using username and password.
    2. cat id_rsa.pub >> .ssh/authorized_keys2
  7. Test your key at the Windows server.
    1. From the Windows server, open a cygwin terminal (Start -> Programs -> Cygwin) and SSH to monitoring server: # ssh -p 22222 -l username monitoring-server-ip .
    2. This time, your key will be used for authentication and you won't be challenged for your login credentials. If you are not logged in automatically, review the previous steps. Or contact your server administrator.
    3. Exit of the Cygwin shell.
  8. Install autossh as a Windows service.
    1. In the Windows server, open a new command Window (Start -> Run -> cmd).
    2. cd C:\cygwin\bin
    3. cygrunsrv -I ModernSupport -p /usr/bin/autossh -a "-M tunnel-monitoring-port-number -R tunnel-port-number:127.0.0.2:3389 username@monitoring-server-ip -p 22222 -g2CN" -e AUTOSSH_NTSERVICE=yes
    4. (for example: c:\cygwin\bin\cygrunsrv -I ModernSupport -p /usr/bin/autossh -a "-M 23043 -R 13043:127.0.0.2:3389 user@22.0.22.122 -p 22222 -g2CN" -e AUTOSSH_SERVICE=yes )
  9. Tweak Windows service settings.
    1. Open the Services management console (Administrative Tools -> Services).
    2. Edit the properties of the AutoSSH service.
    3. In the "Log On" tab, select the "This account" radio button and set the service to run as your current logged in user (typically an administrator-type account).
    4. Start the service.
  10. Test your tunnels.
  11. Consider making a scheduled task to start the service every hour or so, in case autossh goes boom.

Modifed from Reference: http://blog.dhampir.no/content/creating-persistent-ssh-tunnels-in-windows-using-autossh

Was this answer helpful?

« Back