Recipe 17.8. Passwordless Logins for cron Jobs

 < Day Day Up > 

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

     < Day Day Up > 


    Linux Cookbook
    Linux Cookbook
    ISBN: 0596006403
    EAN: 2147483647
    Year: 2004
    Pages: 434

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net