10/31/2007

Using Rsync and SSH

You'll need these packages installed:
  • rsync
  • openssh
  • cron (or vixie-cron)
1. Use SSH without password
Use ssh-keygen command as follows:
$ ssh-keygen -t dsa

Next make sure you have correct permission on .ssh directory:

$ cd
$ chmod 755 .ssh

Now copy file ~/.ssh/id_dsa.pub on Machine #1 (tom) to remote server jerry as ~/.ssh/authorized_keys:
$ scp ~/.ssh/id_dsa.pub user@jerry:.ssh/authorized_keys

Login to your remote server and make sure permissions are set correct:
$ chmod 600 ~/.ssh/authorized_keys

2.Create the sricpt
The script should like this:
#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/home/thisuser/cron/thishost-rsync-key
RUSER=remoteuser
RHOST=remotehost
RPATH=/remote/dir
LPATH=/this/dir/

$RSYNC -az -e "$SSH -i $KEY" $LPATH $RUSER@$RHOST:$RPATH

3. put in cron
When I get the script running successfully, I use 'crontab -e' to insert a line for this new cron job:
0 5 * * * /home/thisuser/cron/rsync-remotehost-backups
for a daily 5 AM sync, or:
0 5 * * 5 /home/thisuser/cron/rsync-remotehost-backups
for a weekly (5 AM on Fridays). Monthly and yearly ones are rarer for me, so look at "man crontab" or here for advice on those.

0 comments: