Greetings
I'm using Ubuntu 10.04 LTS server and Postgresql 8.4.
I have a .sh script that is run by cron every other hour. That works fine.
The .sh script includes an rsync command that copies a postgresql dump .tar file to a remote archive location via ssh. That fails when run by cron; I think because it is (quietly) asking for the remote user's password (and not getting it). I set up the public/private ssh key arrangement. The script succeeds when run manually as the same user that the cron job uses, and does not ask for the password. I am able to ssh to the remote server from the source server (using the same username) and not get the password prompt (both directions), so why doesn't rsync work? I even put a .pgpass file in the root of that user's directory with that user's password, and the user/password are identical on both servers.
I think the problem is rsync is not able to use the ssh key correctly. I tried adding this to my script but it didn't help.
Code:
# start ssh-agent so don't need to enter passwords manually
if [ -d $HOME/.ssh ]
then EXEC="exec ssh-agent"
EXEC="exec ssh-add"
else EXEC="exec"
fi
Here is the rsync command embedding in the .sh script.
Code:
rsync -v -u -a -e "ssh -i /home/postgres/.ssh/id_rsa" --progress --stats $BACKDIR $USER@$DEST:$DESTDIR
Here is the cron entry:
Code:
0 */2 * * * postgres /home/postgres/backups/BST_postgres_backup_service.sh
I also set permissions:
private key file - LOCAL (600)
authorized_keys - LOCAL (700)
authorized_keys - REMOTE (600)
.ssh directory - BOTH (700)
thank you for your help!