Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use file transfer via SSH on some scripts. I've read it's possible to tar over ssh. Where should I start reading?

share|improve this question
Why do you bring up tar? – Zoredache Mar 9 '10 at 19:37
tar is the fastest way to copy files over SSH. scp and rsync have a lot of protocol overhead when copying lots of small files. – Justin Mar 9 '10 at 21:12
@Justin, of course the assumption with tar is that you will have a reliable connection. If raw performance doesn't matter then it is usually better to stick with the more common and simple solutions like scp/rsync. – Zoredache Mar 9 '10 at 22:04
huh? tar over ssh is no worse then scp or rsync. The only aspect in which rsync is better is that it lets you resume. If the connection isn't reliable it is probably still worth it to try tar over ssh first, and then finish the transfer with rsync. – Justin Mar 9 '10 at 22:10
@Justin, that would make a fairly complex script. Perhaps we should start with something just a little more basic. – John Gardeniers Mar 10 '10 at 1:42
up vote 23 down vote accepted

To do file transfer over ssh you can

  • use scp
    • scp -r /srcdir/ user@remotehost:/destdir/
  • use rsync over ssh (see the -e parameter)
    • rsync -e ssh -a /srcdir/ user@remotehost:/destdir/
  • use some tool that transfers data via stdin/out (tar, cpio, etc)
    • cd /sourcedir; tar -c . | ssh username@remotehost bash 'cd /dstdir; tar -x
  • Mount the filesystem via sshfs (if fuse is supported on your system)
share|improve this answer
Pure awesomeness, thanks!! – Fernando Briano Mar 10 '10 at 20:28
I regularly use all three; which one I use depends on the circumstances. – reinierpost Mar 11 '10 at 14:22

O'Reilly has a book with it all - SSH, The Secure Shell: The Definitive Guide - if you Google for it, there are many references, places to buy it, and view it online.

share|improve this answer
Gotta love it when you get downvoted and no comments to let you know why. He asked where to start reading - and this is available online and from a bookstore. It is a great reference for ssh. – Kevin K Mar 22 '10 at 18:38
I think this is wrong too. Why did you get voted down (twice) given that you actually answered the question and the accepted answer (voted up 15 times so far) is a generic how to copy files over ssh with no reference to where to start reading. I'm gonna vote you up, just to try to remedy the situation. Don't let them get you down man. – Richard Holloway Mar 25 '10 at 23:52

Im no expert, but I think is what you want.

share|improve this answer

For tar over ssh, you can use the fact the ssh forwards stdin and stdout. So you can do

ssh server 'tar czf - /some/dir/' > tarfile.tar.gz

and have the backup on the local machine.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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