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.
Why You Need rsync Over SSH
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:
You don’t need rsyncd daemon listening on the remote server
You don’t need to open additional ports (873/tcp for rsyncd) since SSH port 22 is likely to be available out of the box.
How To use rsync with SSH
In most cases, there’s nothing additional needed. But just to be on the safe side, use -e option to specify your SSH intention:
/home/greys/scripts is 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:
$rsync -avhz-e ssh newscripts becky:/home/greys/scripts
sending incremental file list
created directory /home/greys/scripts
newscripts/
newscripts/automount.sh
newscripts/backups.sh
newscripts/jkl.sh
newscripts/mtime-capto.sh
newscripts/mtime-capto2.sh
newscripts/mtime-screenshot.sh
newscripts/mtime-voila.sh
newscripts/mtime.sh
newscripts/plex-mpv.sh
sent 3.75K bytes received 233 bytes 1.14K bytes/sec
total size is 7.44K speedup is 1.87
The Key Benefit of Using RSync
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.
And re-run rsync. See how its output differs from the first run? It only transfers the 2 files that I changed:
$rsync -avhz-e ssh newscripts becky:/home/greys/scripts
sending incremental file list
newscripts/jkl.sh
newscripts/mtime.sh
sent 814 bytes received 67 bytes 195.78 bytes/sec
total size is 7.45K speedup is 8.46
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!