rsync over SSH
I’ve migrated a few rsync pages yesterday and realised there’s been something I’d wanted to document for some time: using rsync over ssh.
rsync initially started as a tool for synchronising local folders, then expanded to also working with external drives, then progressed to working with networking folders and eventually started working with remote servers using its own native rsync protocol.
Modern Linux systems support running rsync over SSH, which gives you best of two worlds: you get remote access AND you make sure your transfer is secure.
Additionally, using SSH transport has two more benefits over the native rsync protocol:
In most cases, there’s nothing additional needed. But just to be on the safe side, use -e option to specify your SSH intention:
In this command line above:
newscriptsis the name in my current location
beckyis the hostname of my Raspberry Pi server
/home/greys/scriptsis the destination directory name - this will be created on becky
The behaviour of rsync command above is that I’ll end up with the exact copy of my local newscripts directory on Macbook with the remote /home/greys/scripts directory.
Let’s run it:
The key benefit is synchronising two specified locations. Simply put, it means if I change a file or two in my local newscripts directory, I won’t have to copy the whole thing over to the remote server - I can use the same rsync command to sync it again and rsync itself will figure out which files must be transferred, saving me time and bandwidth.
So newscripts directory has the following in it:
Let’s change two of the files:
rsync. See how its output differs from the first run? It only transfers the 2 files that I changed:
That’s it for now. Have fun!