Running OpenSSH sshd and MSYS2 rsync on Windows

OpenSSH and MSYS2 make it possible on Windows to use rsync over ssh which is a powerful tool for backup.

For OpenSSH installation, download
https://github.com/PowerShell/Win32-OpenSSH/releases

Basic instructions:
https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

Initially, I got an error running FixHostFilePermissions.ps1. So I omit that step. Then I saw these errors in sshd.log file.

560 13:02:08:686 error: Could not load host key: ./ssh_host_rsa_key
560 13:02:08:687 error: Could not load host key: ./ssh_host_dsa_key
560 13:02:08:687 error: Could not load host key: ./ssh_host_ecdsa_key
560 13:02:08:688 error: Could not load host key: ./ssh_host_ed25519_key
560 13:02:08:688 sshd: no hostkeys available -- exiting.

In my case, I needed to type the following command to run one of scripts.

powershell -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1 Unblock

Next, I got this error after several tries of ssh connection from other computers.

3900 15:23:43:588 error: fork: Input/output error

I did these steps for each exe not to be blocked by antivirus.
Right click .exe -> Properties -> Unblock

For more details, see
https://github.com/PowerShell/Win32-OpenSSH/issues/844

To use public key authorization, you need to make .ssh/authorized_keys file.
On Windows, you need an extra work.

icacls C:\users\username\.ssh /grant "NT Service\sshd":R /T

For more details, see
https://superuser.com/questions/1041957/how-to-properly-configure-win32-openssh-authentication

To install MSYS2, download

http://www.msys2.org

Follow the instruction above.
After that, install rsync

pacman Sy rsync

Make sure /usr/bin of MSYS2 is included in PATH env.
Let’s try running rsync from linux like this.

rsync -azzv -e "ssh -p 20022 -i ~/.ssh/id_rsa" 'Backup@windows-pc:/c/users/someuser/Documents' /srv/share/Documents