15

I'm trying to run a git push from cron. When I do the command interactively on the shell it's going through fine. When running the command from my user's crontab, cron delivers the error message

Permission denied (publickey).

I presume it hasn't to do with finding or reading my ~/.ssh/id_rsa, as I can cat the file from cron alright. UID and EUID are set fine in the cron job. - Any ideas?

UPDATE

I got it working when supplying the environment key SSH_AUTH_SOCK to my cron job, but I'm concerned that this is only valid as long as I'm logged in. I'm looking for a solution that works independent of interactive logins.

ThomasH
  • 22,276
  • 13
  • 61
  • 62
  • What did you end up doing to solve this? For me It wasn't the SSH_AUTH_SOCK variable (tried passing this in the crontab line). I get an error that git credential-osxkeychain isn't a valid git command. – Stephen Turner Mar 12 '13 at 17:11
  • @StephenTurner I log in to the machine without agent forwarding. I start the ssh agent, capturing its output to a file. I (shell) 'source' this file on the shell and call ssh-add (all this in a shell script). The last command will require entry of the pass phrase. As long as the ssh-agent continues running, the cron job just have to source the said file, and then the git push commands run through just fine. - I can't comment on 'git credential-osxkeychain', though (mine runs on linux). – ThomasH Sep 14 '13 at 07:27

1 Answers1

8

As explained here, it can be due to the lack of knowledge from the cron session shell of the ssh agent.
If that is the case (ie if you are using private ssh keys with a passphrase), keychain is the usual solution (as mentioned here).
More details in this example: "Passwordless connections via OpenSSH using public key authentication, keychain and AgentForward".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250