Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Sync two directories with rsync and ssh through the internet

Digital Innovation Partner

Sync two directories with rsync and ssh through the internet

view-refresh2Hello,

we want to sync two directories in two different server that are connected to the internet. We want to use ssh as channel protocol because we already have the firewall rules to connect and because it is encrypted.
First of all we need that machine A will connect to machine B without password asking, this can be achieved by generating public key from machine A and copy it to machine B. Here are the commands:
generate the key from machine A.

the public key will be created in /home/[user]/.ssh/id_rsa.pub

NOTE: if you already have created the public key, calling again “ssh-keygen” will re-generate your public key. This means that if in the past you have already copyed the old public key to another host, that connection will not work untill you re-copy your newly created public key.

then we copy it to the machine B

now we have to append the contents of the file id_rsa.pub in ./ssh/authorized_keys

Now we can connect with ssh from machine A to machine B without password asking.
Now we use rsync from machine A to sync the directories.

After this command we found /dir2/dir1 on machine A, backupped and synced. Put the commands in cron to have sync over time.

We can now sleep peacefully. 🙂

Tags: , , ,

Lascia un commento