Setup rsync server over SSH on Windows Server 2012 easy way

  1. Configuring sshd from Windows server

There’re few options available such as Cygwin, WSL, MSYS2(Git for Windows) and Win32-OpenSSH. Personally I ‘thought’:

  • Cygwin: installing the Cygwin was relatively easy, but configuring the sshd wasn’t. Not providing uninstaller was also minus.
  • WSL: Looked promising, but it didn’t support background daemon.


What this isn’t — WSL is not a Linux server

Just as with WSL on Windows Client, you can run daemons and jobs like MySQL, PostgreSQL, sshd, etc., via an interactive shell, but you cannot currently use WSL to run persistent Linux services, daemons, jobs, etc. as background tasks.

  • Win32-OpenSSH: It’s official way to use the sshd on Windows(It even recently started including OpenSSH from the OS additional features). Detailed instruction, (un)install Powershell scripts are also provided here

So I installed Win32-OpenSSH following by page.

The server already installed the ‘Git for Windows(MSYS2)’ so that I made the bash.exe as a default shell of the sshd.

Name: DefaultShell

Value: C:\Program Files\Git\bin\bash.exe

Few more tweaks required,

  • I appended the client’s public key into the Windows Server(where rsync.exe server will be running)’s ~/.ssh/ authorized_keys
  • The server’s sshd_config file is located at ‘C:\ProgramData\ssh’ (unless you changed). ‘PubkeyAuthentication yes’ option is commented out by default. Let’s enable it.

So far, you should be able to ssh login to the Windows Server and see the MSYS2’s bash.exe shell as the result.

2. Installing rsync on the Server

I was struggling with this part at first because when I googled ‘rsync over ssh windows’ the results were outdated or insufficient. However, I found this and if you’re using MSYS2(Git for Windows), it’s extremely simple. Just grab the compiled binary from msys2 repo and paste it to the bin folder(C:\Program Files\Git\usr\bin).

Refs: &

Then I was able to successfully ‘rsync’ing by:

rsync …… -e ssh -vvv /c/somedir/folderA

Last bonus:

3. Working it through Jenkins

Additional chores remained if you want it to work through Jenkins because Jenkins service process is running under the SYSTEM account (if you didn’t modify). For example, if someone tried to launch a job does Jenkins rsync over SSH, then they’ll see the following error:

[rsync test] $ C:\…\Git\bin\bash.exe -xe C:\Windows\TEMP\

+ whoami


+ rsync … -e ‘ssh -vvv -i /c/Users/xxxxx/.ssh/id_rsa’ /c/….

OpenSSH_7.5p1, OpenSSL 1.0.2k 16 Jan 2017

debug1: Reading configuration data /etc/ssh/ssh_config

: : :

: : :

debug3: hostkeys_foreach: reading file “/etc/ssh/ssh_known_hosts”

debug3: hostkeys_foreach: reading file “/etc/ssh/ssh_known_hosts”

debug1: read_passphrase: can’t open /dev/tty: No such device or address

Host key verification failed.

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.3]

Build step ‘Execute shell’ marked build as failure

Finished: FAILURE

I believe this problem can be fixed by making the Jenkins to run under normal user account, but I approached bit differently by

  • Launching cmd.exe as the SYSTEM privilege using Sysinternals’ PsExec.exe

  • From that console, run bash.exe again and just login to the server once to create known_hosts for %SYSTEMPROFILE%.

One thought on “Setup rsync server over SSH on Windows Server 2012 easy way

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s