Rsync over SSH with key authentication

Using rsync and ssh to synchronize folders over the network.
created by on 2013-01-17

Setup the SSH login with key authentication

Create a new ssh key pair:

ssh-keygen -t rsa -b 2048 -f andy-rsync-key

Move the public(!) key to the remote server:

scp [email protected]:/home/andy/

Append the public key to the “authorized_keys” on your remote server:

ssh -l andy
cat >> .ssh/authorized_keys

Test the connection:

ssh -l andy -i ~/.ssh/andy-rsync-key

You should not be prompted for a password.

Setup the folder synchronization

Test the synchronization:

rsync --progress -avz -e "ssh -i /home/dev/.ssh/andy-rsync-key" /home/dev/git-master/ [email protected]:/home/andy/git-master/

Create a shell script for the synchronization

vi ~/bin/

rsync –progress -avz –delete -e “ssh -i /home/dev/.ssh/andy-rsync-key” /home/dev/git-master/ [email protected]:/home/andy/git-master/

chmod 700 ~/bin/

Schedule the script execution (every 5 minutes):

crontab -e
# m h  dom mon dow   command
*/5 * * * * /home/dev/bin/


Fork allmark on GitHub