Pushing to GitHub using cron job - Permission denied (publickey)
I created an SSH key (following the official tutorial ), added it to GitHub, and created a Bash script that commits and pushes one file to my repository on Github. When I run this script from the command line everything works fine and updates are pushed. However, when I set up the job with crontab -e
, clicking generates the following error:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
I edited the user's crontab ( crontab -e
) i.e. I am NOT using sudo crontab -e
. I am running Ubuntu 12.04.
source to share
if it is not a user issue (where you run the job as root, the right $ HOME / .ssh folder is missing) it might be a problem with the phrase :
it turns out that I was wrong and the ssh key is password protected (when booting the keychain ssh-agent), so why didn't it work with the script, but not when running from a bash session.
Adding. ~/.keychain/$HOSTNAME-sh
to my script solved the problem.
The passphrase bit is detailed in Can't ssh to remote machine using shell script in Crontab :
You can make ssh connections inside a cron session. You need to set up public key authentication to be able to access without access.
For this you need to have itPubkeyAuthentication yes
on every remote serversshd_config
.
source to share