I have a local copy of a Bitbucket repo on one of my servers (under the user rob), and I created a script that runs every hour in cron and attempts to pull & update the local copy. The issue I'm having is that hg pull
fails, even though when I follow the same procedure outside of cron it works fine.
I setup an ssh key for accessing Bitbucket in the normal fashion (i.e. followed the guide in the Bitbucket docs) and then the repo was initially cloned with
cd /home/rob
hg clone ssh://hg@bitbucket.org/robjohncox/tools
The update script at /home/rob/bin/update_tools.sh
is:
#! /bin/bash
cd /home/rob/tools
hg pull >> /tmp/update_tools.log
hg update >> /tmp/update_tools.log
And the crontab for user rob is:
0 * * * * /home/rob/bin/update_tools.sh
All very simple. However, when the job runs, we see that the call to hg pull
fails with the output
remote: Permission denied (publickey).
Does anyone have an idea why this may be happening - is there some other step that I need to take so that when cron runs it has access to the relevant public key? The update_tools.sh
script runs fine from a shell.