Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy file with rsync or scp over multiple level or hops of SSH

I need to transfer around 4.2 GB of files from my local computer to a server B. However to ssh into server B, I need to ssh into server A.

Currently I'm copying files from my local computer to server A and then from server A to server B.

So the flow goes like this:

rsync -avz --del ~/Desktop/abc/ <my-user-name>@<server-A>:~/abc

rsync -avz --del ~/Desktop/abc/ <my-user-name>@<server-B>:~/abc

This is slow and copies 4.2 gb of data two times instead of one!

Can I transfer files with rsync from my local computer to directly server B ?

like image 653
arpit Avatar asked Nov 08 '15 20:11

arpit


1 Answers

You can always use ssh with proxy command, which allows you to transfer files transparently. Using this config (~/.ssh/config):

Host <server-A>
    User <user-A>

Host <server-B>
    User <user-B>
    ProxyCommand ssh <server-A> -W %h:%p

You can call your rsync:

rsync -avz --del ~/Desktop/abc/ <server-B>:~/abc

The data will be only "routed" over the middle host.

like image 182
Jakuje Avatar answered Oct 22 '22 07:10

Jakuje