How to rsync directly into a Windows 10 machine (using OpenSSH not cygwin or WSL)
Windows 10 is getting closer and closer to the Linux world every day, and it’s hecking exciting.
One thing I needed to do recently was to send some files from an Ubuntu machine over to a Windows 10 machine. In the past, I would either install Cygwin or install an Ubuntu instance using WSL. This time, I wanted to see how “native” I could go, and boy, was it a lightweight experience!
The steps here are nothing profound, but I wanted to share how I did it. I pieced the solution together by Googling multiple things, so hopefully this saves someone some time.
- The first thing you need to do is install OpenSSH server on your Windows 10 machine. The basic gist is:
- Open Settings →Apps →Apps & Features →Optional Features
- Install OpenSSH server (if it’s not already installed)
- Open Powershell (in adminstrator mode)
- Start the service:
Start-Service sshd# Optionally, set it to turn on automatically every time:
Set-Service -Name sshd -StartupType 'Automatic'
- If you install the optional feature but it doesn’t show up in Powershell (i.e., can’t Start-Service sshd), then you might need to apply some Windows system updates. Update all the way to the latest patch and try installing the optional feature again.
2. Go to your Linux box and test the connection
- You’ll need to know your Windows 10 username, so open up Powershell and type this:
# example output: BOBCAT\tomcat
- The command will return: <machine_name>\<username>. The part that you want is the “username” part (ignore the machine_name).
- The password will be the same one that you use to login to your computer with. It’s either your Microsoft (Outlook) account password or your local computer username password, depending on your sign-in method. You could set up key files instead, if you’d like.
# eg: ssh email@example.com
3. Rsync time!
- The command to rsync from an Linux box to a Windows machine is:
rsync -avP --rsync-path='wsl rsync' <file_to_send> <username>@<host_ip>:<path>
OK, let’s break that down…
- The “-a” option is archive-mode, which tries to preserve time stamps, “-v” is verbose, and “-P” is progress indicators.
- The “rsync-path” option is where the magic sauce happens. It tells the Windows 10 machine where to find its own rsync application. Without this option, the Windows 10 receiver machine will complain that it can’t find rsync.
- The one last tricky bit is the “path” at the end. I haven’t fully tested this, but in my experience, the back-slashes that Windows uses (e.g., C:\User\username) does NOT work. For example, when I tried to rsync to <username>@<host_ip>:Desktop\subfolder, it ended up creating a folder named “Desktopsubfolder” in my user directory. Perhaps forward-slashes will work, or maybe some combination of double back-slashes (e.g., “Desktop\\subfolder”) so that the first back-slash is escaping the second back-slash.
That’s it! I hope it’s helpful to someone out there. And also to future-me, because I know I’ll forget the next time I need to do this again…