[Unix/Linux] Backup with rsync and sshkey (private key) (English)

You need to sync files between 2 Unix based systems? Why dont you use SSH to transfer the files crypted between. Here i show you how:

The first step is to login on our source system and create a private key/public key pair.

ssh-keygen -t rsa -b 4096

when you get asked for the directory use the default (/home/<user>/.ssh/id_rsa)

dont enter a passphrase in the next step!

now your keys are generated 🙂 and in your (/home/<user>/.ssh/) directory.

In the next step you should rename the id_rsa.pub to authorized_keys. (before u might safe the id_rsa.pub to a safe place for other uses)

mv id_rsa.pub authorized_keys

After that u need to copy the id_rsa to your destination system and give the the file chmod 0700

chmod 0700 id_rsa

And now u can use rsync in combination with the key to communicate with the servers

rsync -av --delete -e "ssh -p [ssh port] -i /root/.ssh/id_rsa" [user]@[ip]:/path/to/file/on/source /path/to/file/on/destination