This is the first part of the Availability Anywhere series. For your convenience you can find other parts using the links below:
Part 1 — Connecting to SSH tunnel automatically in Windows
Part 2 — Connecting to VPN automatically in Windows

Let’s say that you want to configure reverse tunnel for connecting to your laptop computer. How to do that so it is started automatically when you boot your machine and it is reliable? In this post I will describe my configuration which I use for almost 10 years now. It is old and I bet there are better solutions available but I wanted to use something built into Windows with minimal dependencies needed. I am using this since Windows 7 and it still works. It opens tunnels for me so I can RDP into my machine from any place in the world.

Kitty

First, you need to have an SSH tunnel. For that you can use Kitty, a fork of Putty which gives some more options. It can save password (if you want to go with it instead of keys) and has options for restarting.

Basically, I use this configuration:

It’s quite big but there are only few important things which you need to configure:
In Window -> Behaviour deselect “Warn before closing window” to be sure.
In Connection set a keepalive to something like 10 and anti-idle string to something like test. Also, select to “reconnect on system wakeup” and “reconnect on connection failure”.
In Connection -> Data choose your username and password.
In Connection -> SSH -> Tunnels choose your ports. I am forwarding 3389 (RDP), 5985 and 5986 (PS Remoting), 22 (OpenSSH).
In Session choose “Always” for “Close window on exit”.

Make sure to connect manually at least once to accept the key and you should be good to go.

Task scheduler

Now you need to run this thing automatically on system start. I am using this script:

Save this as a bat file.
Next, I noticed that sometimes I cannot RDP to my machine using the same user which actually runs this script. So I create new user in the system (it can be a local one, no need to use domain one), give it permissions to kitty and session file, run session (to accept the key). Then I use this Task scheduler:

Write this as an XML file, import to task scheduler, adjust paths, enter password for Author user and restart the operating system. Make sure you enable history logging in Task Scheduler to have some logging in case of errors.