I have a repository for storing all my configs (e. g. .ssh/config). From time to time I need a backup them, so I need to run these commands
git commit -am 'Auto git backup `date -I`'
git push origin master
It is pretty annoying so I decided to make a cron job, which runs simple script with these lines above. I ran crontab -e
and added new line at the end of file. I also replaced git
with which git
inside of script. git commit
command works perfectly in contrast with git push
. When I made some debug prints I got
ssh: Could not resolve hostname bitbucket.org: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
But when I run script manually, it works. I think it is because of SSH aliases in my .ssh/config
, which looks like
Host bitbucket.org-personal
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host bitbucket.org-work
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/another_id_rsa
Does somebody have idea, how to propagate SSH aliases to environment, which runs cron jobs? Also maybe I am wrong and problem is caused by something else.