Tag: rsync

These instructions can be used to securely and automatically rsync files between 2 computers (Linux or Mac) either on your local network or even across the Internet using certificates/keys instead of passwords. Syncing files between 2 computers without using passwords is really not as difficult as it may seem, trust me!

The instructions below are combination of how-to guides I have found online and my own personal experience setting up syncing between computers. This guide is written from the perspective of using Ubuntu Linux, but the majority of the commands would be the same on any flavor of Linux or even Mac OS X.

In this scenario I reference two computers:

Server A: This server is the remote host (the one that will be receiving files)

Server B: This server is the connecting host (the one that will be sending files).

Goal:

Automatically back up/rsync a folder from one Web server to the other every 10 min. securely but without passwords.

Step 1: Generate SSH Keys

Login to Server B (connecting host) as root

cd /home/%user% or cd /home

On connecting host (Server B), Generate keys:

ssh-keygen -t dsaGenerating public/private dsa key pair.Enter file in which to save the key (/root/.ssh/id_dsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /root/.ssh/id_dsa.Your public key has been saved in /root/.ssh/id_dsa.pub.The key fingerprint is:c1:17:3a:1d:d6:b7:ea:a1:d8:d7:38:91:76:02:d8:86 root@serverb.domain.com

Step 2: Create User on Server A

Login to Server A (remote host)

Create user on remote host: useradd %user%

Step 3: Copy Key Pair to Server A

Copy Key pair to home folder of user you just created From Server B (connecting) to remote host Server A (remote)

scp /root/.ssh/id_dsa* root@servera.domain.com:/home/%user%

Step 4: Install Keys/Certificate

Login as rsync user on Server A (remote) (**Hint: This is the user you created in Step 2**)

Step 5: Install Rsync

**Hint: Be sure that you are running rsync 3.07 or later. These options “- vzrtn” are what worked for me, but depending on what you need you may want to change them. Also keep in mind that the “- n” option is only for a dry run and should be removed when creating your script below in step 6.**