How to create SSH tunnel on Windows by using AutoSSH

Step 1: download Cygwin
Step 2: Install Cygwin
Step 3: Open Cygwin terminal

Follow step 1,2,3 in this tutorial: How to install SSH daemon on Windows

Step 4: Generate a public/private key pair

Use this commandline:


Use empty passphrase:


$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Administrator/.ssh/id_rsa):
Created directory '/home/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/Administrator/.ssh/id_rsa.
Your public key has been saved in /home/Administrator/.ssh/
The key fingerprint is:
SHA256:YsEPYiYtiTkN+jbNkRvK6mc29EQVFD9Qbp89euZmpS9 Administrator@MRNC-N9NJM89QFO
The key's randomart image is:
+---[RSA 2048]----+
|.     .=+.       |
|.= o o .+        |
|= = O =  =       |
| + O * +. o o    |
|  * = o S  o o   |
| o o o .    . .. |
|. . o      . oo  |
|.  = .      +E   |
| .+ .       o.o. |

Step 5: Copy your newly-created public key to the SSH server

scp .ssh/


scp .ssh/


$ scp .ssh/'s password:                                    100%  411     0.4KB/s   00:00

Step 6: Login SSH server

mkdir .ssh
cat >> .ssh/authorized_keys


$ ssh's password:
Last login: Sat May  7 08:05:24 2016 from xx.xx.xx.xx
[root@tutorialspots ~]# mkdir .ssh
[root@tutorialspots ~]# cat >> .ssh/authorized_keys

Step 7: Test key

In the previous step, we create a key in the SSH server, now we test it.

7.1 Use command line: exit to logout SSH server

7.2 Login again


If you see the result: (don’t require type password)

$ ssh
Last login: Sat May 21 07:32:29 2016 from xx.xx.xx.xx
[root@tutorialspots ~]#

It means these above steps are successful. Otherwise, they are false.

7.3 Do like step 7.1

Step 8: Install autossh as a Windows service

In the Cygwin terminal, use this commandline:

cygrunsrv -I AutoSSH -p /path/to/autossh -a "-M 20000 -L localaddress:port:serveraddress:port" -e AUTOSSH_NTSERVICE=yes


cygrunsrv -I AutoSSH -p /bin/autossh -a "-M 20000 -L" -e AUTOSSH_NTSERVICE=yes

Step 9: Tweak Windows service settings

9.1: Run: services.msc
9.2: Properties

autossh service properties

9.3 Go to tab Log On, then choose your current user

autossh service properties user

9.4: Start this service

Step 10: test tunnel

Example: Read the next tutorial: How to connect Mysql server through SSH tunnel using AutoSSH


Get status from windows server

cygrunsrv --query AutoSSH


$ cygrunsrv --query AutoSSH
Service             : AutoSSH
Current State       : Stopped
Command             : /bin/autossh -M 20000 -L

Remove windows service

cygrunsrv --remove AutoSSH