0

I have a very simple cron job written in shell script, which scp a file from another server to local. e.g,

#!/bin/bash
scp $REMOTE:/$FILE ./

Of course, the server need a private key to login, which I have config file saving HostName, IdentityFile in (~/.ssh/id_rsa, a mod with 600).

However, it has "permission denied" issue when the cron running....

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/xxx>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=xxxx>
Message-Id: <20120118235702.33A7B16C03B5@xxx-xxxx-deskbox>
Date: Wed, 18 Jan 2012 18:57:02 -0500 (EST)

Permission denied (publickey).

I checked everywhere, it says the crontab will be running as the owner/user's environment.

Anyone have a solution for this? Thanks!

warren
  • 19,297

1 Answers1

1

Problem solved. There was a passphrase on my id_rsa key. Hence manually running won't require it as the phrase is in the session; while crontab need the passphrase. Delete the passphrase

ssh-keygen -p [-P old_passphrase] 

and enter empty for new passphrase; or check this page

Hope my answer can help some programmers several hours of debugging..