22

I am currently away from my LAN and I need to do a backup of my laptop. I have a somewhat recent copy of my laptop on my server and I usually back the laptop up using rsync. Now I wish to do that, but outside of my LAN.

In short I want to send data from A to C via B, where A is my laptop, B my router and C my server.

I found this command: A$ scp -oProxyCommand="ssh B nc %h %p" thefile C:destination, that works fine for transferring files via scp - but since I already have most of the data on my server I wish to use rsync to only sync the delta.

I have tried: A$ rsync file -e 'ssh B ssh' C, and that works as far as I am prompted to give the password for user:C. However, when I enter the password nothing happens. The router is running Tomato v1.28 and I am unable to set it up to utilize an ssh config file to enable it to log onto C w/o a password.

Any ideas on how to make this work?

  • 2
    use the same ProxyCommand in the configuration file. Rsync should pick that up. – Jakuje Aug 20 '16 at 15:37
30

This question is essentially answered elsewhere, including here for scp and here for rsync. Since the latter includes my answer, but no answer was accepted, I'll repeat it here.

As you noted, you can use rsync's -e | --rsh option, but it's going to be a bit more complicated:

rsync -azv -e 'ssh -o "ProxyCommand ssh -A PROXYHOST -W %h:%p"' foo/ dest:./foo/

Or, if your version of ssh is new enough (OpenSSH >= v7.3), you can use the -J (ProxyJump) option

rsync -azv -e 'ssh -A -J USER@PROXYHOST:PORT' foo/ dest:./foo/

Note that I'm using -A (agent forwarding) but it should also work with password authentication if you don't use keys, and, of course, you can replace proxy with B and dest with C in your example.

If by chance you don't have a new enough ssh version (>= 5.3, IIRC), you can use netcat instead of -W option to ssh:

rsync -azv -e 'ssh -o "ProxyCommand ssh -A PROXYHOST nc %h %p"' foo/ dest:./foo/

Finally, as noted in comments already, you can put the ProxyCommand into your $HOME/.ssh/config file so you don't have to have such a complicated command line. Specifically, add something like this:

Host C
  ProxyCommand ssh -A PROXYHOST -p 22 -W %h:%p

Or, using ProxyJump for OpenSSH >= v 7.3:

Host C
  ProxyJump PROXYHOST

Then you should be able to just do:

rsync -azv foo/ C:./foo/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.