Tutorial: Backup from Windows with putty / plink to a sftp server

Hi! I wanted to use restic to backup from a windows computer to a linux sftp server.
I found some hints in serveral threads, i just wanted to share my commands with you.
I did not use the Windows 10 implementation of OpenSSH because some older windows server systems do not have it.

Step 1: install putty via the installer https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
It will install plink.exe which we will need.

Step 2: Create a public/private keypair and install the public key of the server. Do NOT set a password for the private key
You can find hints how to do it here:
https://www.ssh.com/ssh/putty/windows/puttygen
(or google some more links - I am not allow to post more than two links here)
Check with putty that you can login to the server without the need for a password

Step 3:
Download restic for windows, I renamed the exe to restic.exe

Step4: Connect to the SFTP Server by using plink.exe
These are the commands that worked for me:

Login with private key to init a repo (replace init at the end with your restic command)
Here: username = demo

C:\Users\Peter2\Desktop\restic\restic.exe -o sftp.command="'C:\Program Files (x86)\PuTTY\plink.exe' -s -l demo -P 22 -i 'C:\Users\Peter2\Desktop\restic\private.ppk' 192.168.1.190 sftp" -r sftp:demo@192.168.1.190:/home/demo/restic init

Please be careful with the use of double quotes " and single ’ quotes. the sftp.command is surrounded by double quotes " and the path to plink and the path to the ppk-file are surrounded by single quotes ’ !

Here is version for use with a password:

C:\Users\Peter2\Desktop\restic\restic.exe -o sftp.command="'C:\Program Files (x86)\PuTTY\plink.exe' -s -l demo -P 22 -pw 12345 192.168.1.190 sftp" -r sftp:demo@192.168.1.190:/home/demo/restic init

(Use stats instead of init at the end for testing).

Then use your normal restic commands.

2 Likes

Thanks for this usual compilation of information!

I have looked at the environment variables. Am I mistaking when I say that there is no way to pass the -o sftp.command ... via env vars?

It’s not possible to pass -o sftp.command via environment variables and it’s unlikely that this will change in the future, see https://github.com/restic/restic/issues/1233 for a discussion.
Just use a wrapper script around restic to inject the option.

Thanks. So I understand that maybe a config file will exist in the future w/ all the config options.

Currently I have a wrapper script indeed. For the background task there is absolutely no issue. It’s a bit awkward when I type various commands (e.g. check, restore, etc). Currently I use restic on Win. When I’ll use it for my linux machines, I won’t need this option any more. So there the need of a wrapper script will disappear maybe.