So sometimes you have a folder on one machine that you just need on another one.
We are GREAT FANS of ssh, and we think it’s a perfect secure tunnel for performing such operations. So the question asked was how do you synchronise /path/to/folder on the local machine to a remote machine using:
- Linux Ubuntu
- A private SSH keyfile
- Over a non-standard SSH port
Well, since this linux, it’s actually rather boringly easy:
rsync -r -a -v -e 'ssh -p12345 -i .ssh/rsa-keyfile' /path/to/folder email@example.com:/home/username/path/to
This copies (if necessarily CREATING) ‘folder’ on the local machine to our remote one. There are however some very important details.
Do NOT add a training ‘/’ to the paths if you want rsync to automatically create the directories. So use this:
The latter copies the files (and sub-directories) in /path/to/folder, whereas the former copies the folder, its contents and all its sub-directories, and thus creates the directory ‘folder’ at the remote machine if it does not exist.