1

I have a working rsync setup between Mac OS X Server and Linux Centos when run manually in a terminal.

I enter the rsync command, it asks for the password, I enter it and off it goes, runs and completes.

Now I know thats working I set out to fully automate it via cron.

First off I create an SSH authorized key by running this command on the Mac server:

ssh-keygen -t dsa -b 1024 -f /Users/admin/Documents/Backup/rsync-key

Entering the password and then confirming it. I then copy the rsync-key.pub file accross to the linux server and place in the rsync user .ssh folder and rename to authorized_keys:

/home/philosophy/.ssh/authorized_keys

I then make sure that the authorized_keys file is chmod 600 in the folder chmod 700.

I then setup a shell script for cron to run:

#!/bin/bash

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/Users/admin/Documents/Backup/rsync-key
RUSER=philosophy
RHOST=example.com
RPATH=data/
LPATH="/Volumes/G Technology G Speed eS/Backup"

$RSYNC -avz --delete --progress -e "$SSH -i $KEY" "$LPATH" $RUSER@$RHOST:$RPATH

Then give the shell file execute permissions and then add the following to the crontab using crontab -e:

29      12      *       *       *       /Users/admin/Documents/Backup/backup.sh

I check my crontab log file after the above command should run and I get this in the log and nothing else:

Feb 21 12:29:00 fileserver /usr/sbin/cron[80598]: (admin) CMD (/Users/admin/Documents/Backup/backup.sh)

So I asume everything has run as it should. But when I check the remote server no files have been copied accross.

If I run the backup.sh file in a terminal as normal it still prompts for a password but this time its through the Mac Key chain system rather than typing into the console window. With the Mac Key Chain I can set it to save the password so that it doesnt ask for it again but Im sure when run with cron this password isnt picked up.

This is where I'm asuming where rsync in cron is failing because it needs a password to connect but I thought the whole idea of making the SSH keys was to prevent the use of a password. Have I missed a step or done something wrong here?

Thanks

Scott

1 Answer 1

4

You can create keys without passwords, when it asks for it just press enter and you will get a key with no password set. Use this key only for trusted internal connections.

Then using this key with cron should work.

3
  • Ok I'll try this. I assume by just pressing enter when it asks for a password is making a key with no password?
    – Scott
    Commented Feb 21, 2011 at 14:36
  • Thanks. This worked. I miss understood that when it was asking for a password I thought it was asking for the password of the existing connection setup.
    – Scott
    Commented Feb 21, 2011 at 14:48
  • No, the password is the NEW key password, if you want to set one. If you don't want a password just leave it empty and press enter.
    – rems
    Commented Feb 21, 2011 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .