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?

  • Why do you bring up tar? – Zoredache Mar 9 '10 at 19:37
  • 1
    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
  • 1
    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

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)
  • 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.

  • 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 http://en.wikipedia.org/wiki/Secure_copy is what you want.


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.

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.