Availability Anywhere Part 1 — Connecting to SSH tunnel automatically in Windows

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
Part 3 — How to enable PowerShell remoting in Windows
Part 4 — Fixing LogonUi hang
Part 5 — Various remote connection things
Part 6 — Task scheduler not running on next run date on Windows Home edition
Part 7 — gpedit.msc on Windows Home
Part 8 — Running interactive application on a remote server from shell
Part 9 — Poor man’s channel bonding for RDP
Part 10 — Slightly better poor man’s channel bonding for RDP
Part 11 — Keeping a channel fresh
Part 12 — FileProxy for avoiding VPN without split tunneling (also known as TCP over File System)
Part 13 — Optimizing FileProxy
Part 14 — TCP over Named Pipe
Part 15 — TCP over Serial Port
Part 16 — Forwarding port from host to docker
Part 17 — Splitting physical monitor into multiple
Part 18 — Binding same port for multiple docker containers
Part 19 — Banning RDP and SSH attacks
Part 20 — Nested full-tunnel VPN in another full-tunnel VPN with force tunnel mode
Part 21 — Fixed mstsc.exe broken UI
Part 22 — Customer Experience Improvement Program restarts
Part 23 — RDP over VR goggles with no PCVR
Part 24 — Make RDP retain position of windows and stop moving them around
Part 25 — Supercharge your VR experience
Part 26 — Working remotely like a pro
Availability Anywhere Part 27 — Tools for remote work from laptops and XR/VR/AR

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.