Remote copy directories and files through an SSH tunnel host

rsync -avz -e 'ssh -A sshproxy ssh' srcdir remhost:dest/path/
If you have lots of remote hosts sitting "behind" an ssh proxy host, then there is a special-case use of "rsynch" that allows one to easily copy directories and files across the ssh proxy host, without having to do two explicit copies: the '-e' option allows for a replacement "rsh" command. We use this option to specify an "ssh" tunnel command, with the '-A' option that causes authentication agent requests to be forwarded back to the local host. If you have ssh set up correctly, the above command can be done without any passwords being entered.

By: totoro
2009-03-25 21:29:07

What Others Think

This is neat. I'm sure many people (including myself) don't know enough about forwarding credentials and other ssh tricks.
bwoodacre · 692 weeks and 1 day ago
ssh rocks!
alperyilmaz · 692 weeks and 1 day ago
Hi. I need to encrypt transfers and I am not sure if rsync does encrypt from sshproxy to my pc.
hectorlara · 609 weeks and 6 days ago
@hectorlara, using the ssh tunnel does, in fact encrypt the rsync contents between the end points. Please read "man rsync" for more details, such as using an encrypted tunnel to an rsync daemon.
totoro · 609 weeks and 4 days ago
Covid had changed our life to another level. I cook, eat more than I work. I get time to spend with my family, doing whatever I kept pending. But the never-ending increase in the number of patients is really worrying.
TwanGrey · 76 weeks and 6 days ago
Thanks for the code you have shared here about the remote copy directories and files through an ssh tunnel host which is a new topic for everyone and everything related to it is very well explained here and hope it is helpful Effect Of CBD
Kaitlyn · 67 weeks and 1 day ago
seofox · 31 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: