sonia hamilton – life on the digital bikepath – sonia@snowfrog.net

9 June 2009

Source keychain credentials in Perl

Filed under: Perl, Ssh — Sonia @ 12:16

I use keychain for securely caching my ssh key credentials when running scripts from cron.

Here’s how to use keychain with Perl scripts:

Create a wrapper script:
source ~/.keychain/hostname-sh
run_perl_program.pl

To run a one-off command do:

system("source ~/.keychain/hostname-sh; cmd");

2 Comments »

  1. nice tip.

    dont forget your soon to be new friend Net::SSH::Expect
    you can apt-get it in debian, dont know about ubuntu

    libnet-ssh-expect-perl

    Comment by Dean Hamstead — 9 June 2009 @ 13:22

  2. Yes I was looking at Net::SSH::Perl too (has better handling of stderr than SSH::Perl) and noticed Net::SSH::Expect. I’m on old fan of Expect, having had to script in the past nasty things like password changes on ‘n’ boxes. Perl integration is nice – not Yet Another Language (TCL) to master.

    Comment by Sonia — 9 June 2009 @ 13:38


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.