通过cron + ssh-agent git push(无密码)

时间:2016-03-14 21:25:30

标签: git bash ssh cron

由于已经出现这种情况,只是希望将相关的帖子排除在外:

许可被拒绝(公钥);不是我的问题:

最接近的是什么让我在哪里,但不为我工作:

的最后一个没有任何迹象,确切地说,导致最佳答案被标记为已解决,但我对建议的故障排除脚本或手动无密码/ ssh-没有任何问题基于代理的推送到github。

我有一个写入日志的python文件,我希望每分钟从我的树莓派中自动推送到github。这是脚本:

~/dir/script
export HOME=/home/uname
cd /home/uname/dir/
echo $HOME
pwd
whoami
python2 ./python-script.py
git commit -am "update"
git push

当我手动运行时,我得到以下输出:

$ ./script 
/home/uname
/home/uname/dir
uname
done ### print from script
[master 0db9599] update
 1 file changed, 1 insertion(+), 1 deletion(-)
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 306 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To uname@github.com:uname/repo.git
   def0bed..0db9599  master -> master

所以,一切看起来都很棒!

这是crontab行(通过crontab -e编辑为常规用户):

*/1 * * * * /home/uname/dir/script

这是journalctl运行后的cron日志:

CROND[13791]: pam_unix(crond:session): session closed for user uname
crond[13862]: pam_unix(crond:session): session opened for user uname by (uid=0)
CROND[13863]: (uname) CMD (/home/uname/dir/script)
CROND[13862]: (uname) CMDOUT (/home/uname)
CROND[13862]: (uname) CMDOUT (/home/uname/dir
CROND[13862]: (uname) CMDOUT (uname)
CROND[13862]: (uname) CMDOUT (done)
CROND[13862]: (uname) CMDOUT ([master 4fd590d] update)
CROND[13862]: (uname) CMDOUT ( 1 file changed, 1 insertion(+), 1 deletion(-))
CROND[13862]: [50B blob data]
CROND[13862]: (uname) CMDOUT (fatal: Could not read from remote repository.)
CROND[13862]: (uname) CMDOUT ()
CROND[13862]: (uname) CMDOUT (Please make sure you have the correct access rights)
CROND[13862]: (uname) CMDOUT (and the repository exists.)
CROND[13862]: pam_unix(crond:session): session closed for user uname

通过谷歌搜索以确保用户已正确设置为github,我尝试了接受的答案here中显示的显式命令:

git push ssh://uname@github.com/uname/repo.git

我不是git专家,所以我认为这只是github上的一个例子 但它看起来也很好用:

git push ssh://git@github.com/uname/repo.git

我还尝试了same answer above~/.ssh/config建议。即:

$ cat ~/.ssh/config
Host github-project1
User git
HostName github.com
IdentityFile ~/.ssh/id_rsa.pub

然后:

git remote add github-project1 github-project1:uname/repo.git

我得到了与我尝试的所有变种相同的结果;手动推送,脚本执行正常但cron失败。

我还可以检查什么?

1 个答案:

答案 0 :(得分:1)

  

通过cron + ssh-agent git push(无密码)

Cron通常无法访问您的ssh-agent,因为您的shell中存在环境变量$SSH_AUTH_SOCK,但它可能不在cron使用的那个。< / p>

相关问题