Copy Local Files into Remote Server through n>1 SSH Hops

Copy your local files into a remote environment with an arbitrary number of hops using the following:

$ rsync -have "ssh -A -t user@middleman ssh -A -t user@destination" source_path :target_path

As in, copy your local directory ‘foo’ to the root path of your staging server using:

$ rsync -have "ssh -A -t user@middleman ssh -A -t user@destination" foo :

Notes:

  1. If you are copying a directory, remember the target path should be the target directory’s parent folder.
  2. If you are using this (‘hot-deploying’) instead of a traditional ‘deploy’ from a version-controlled repository, exercise the appropriate caution: verify your files have been copied to the correct location, remember they haven’t necessarily been source-controlled, and so on.
  3. I learned this from: http://mjbright.blogspot.co.il/2012/09/using-rsync-over-multi-hop-ssh.html

Hooray for Science!

Advertisements