Previous Section  < Day Day Up >  Next Section

Recipe 17.8. Passwordless Logins for cron Jobs

17.8.1 Problem

You want to schedule some backups or file transfers via SSH, using cron. How do you tell cron to look to keychain to handle authentication of remote hosts?

17.8.2 Solution

Use the same source line in your cron scripts that you used in your .bash_profile. This is a simple script that uses rsync to back up a user's home directory:

#!/bin/bash

source  /home/saz/.keychain/$HOSTNAME-sh

rsync -a -e ssh --delete --force rsync.test.net::home/saz/  /backups/saz

Slap it in a cron job, and you're fully automated until the next reboot.

17.8.3 Discussion

Again, using null-passphrase keys leaves your private keys wide open to being misused by anyone who gains access to them. Using keychain ensures that you can properly protect your SSH keys with passphrases and still automate SSH transfers.

17.8.4 See Also

  • ssh(1), keychain(1)

  • Chapter 16

  • SSH, The Secure Shell: The Definitive Guide

    Previous Section  < Day Day Up >  Next Section