Q: http://stackoverflow.com/questions/7994663/git-push-via-cron
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.
A:
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".
Very brief synopsis
1. Generate private/public key pair (id_dsa and id_dsa.pub).
Save private key in ~/.ssh/id_dsa on trusted hosts you will ssh from.
Append public key to ~/.ssh/authorized_keys on hosts you will ssh to.
Do not use ~/.ssh/authorized_keys2. If you see that file, remove it
and upgrade to a recent version of SSH.
2. Set ForwardAgent yes in ssh_config on all hosts you ssh
from. Set PubkeyAuthentication yes in sshd_config on all
hosts you ssh to. Maybe set StrictModes no in sshd_config.
3. Install keychain then configure by adding the following lines
to your $HOME/.bash_profile:
/usr/local/bin/keychain $HOME/.ssh/id_dsa
source $HOME/.keychain/${HOSTNAME}-sh
4. For crontab scripts that use ssh, add the following line in
order to avoid having to manually enter a passphrase:
source $HOME/.keychain/${HOSTNAME}-sh
5. ssh from host to host without needing to enter passwords. Where
you can ssh, you can also scp, sftp, etc., all securely but without
having to enter your passwords on the various hosts you use.