Tuesday, March 25, 2008

How to ssh-add in cron job

EDIT: updated link in this article.

ssh-add can let your ssh-agent remember the passphrase of your ssh
secret key, so that you don't need to type any password when loging
into a remote machine.
However, it is an interactive program, you can't call it in a cron
job. Even if you can, you will expose your passphrase in a file, which
is not safe.

The solution is actually very easy. You don't really need to ssh-add.
All you need to do is letting ssh know some environment variable.

First of all, I recommend you set up ssh-agent forwarding with GNU
screen following instruction here:
http://www.deadman.org/sshscreen.php
Then in your cron job script, source ${HOME}/bin/fixssh first.
Done!

Enjoy ;)

3 Comments:

Blogger geekounet said...

Keychain was designed for this job too ;)

3/25/2008 9:18 AM  
Blogger Zhang Le said...

Thanks! ;)

3/25/2008 1:16 PM  
Anonymous Anonymous said...

The URLin the article is stale.

1/27/2010 11:55 AM  

Post a Comment

Links to this post:

Create a Link

<< Home