【发布时间】:2019-09-21 19:30:41
【问题描述】:
我正在设置一个服务器,我希望我的服务器中的 git 存储库与源服务器 (Github) 保持同步。我试图运行一个 cron 作业,它每分钟更新一次服务器中的存储库。这在我的 mac 电脑上是成功的。
crontab:
* * * * * bash /home/ubuntu/venv/App/deployer.bash >> /home/ubuntu/venv/App/Logs/deployer.txt 2>&1
这是服务器中出现故障的部分:
git fetch --all
git reset --hard origin/master
错误:
Fetching origin
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
error: Could not fetch origin
在 crontab 之外一切正常。 例如 : 我可以在没有 sudo 的情况下在 git repo 中执行所有 git 命令。 使用 sudo 我得到与 cronjob 中相同的错误。
更新:
找出导致问题的原因:
crontab 表达式中的2>&1 正在写入标准错误,并且非常正确。 当我在 crontab 之外运行命令时,它从未请求过身份验证。但是在每次执行的 crontab 上,命令都在请求身份验证
现在谁能解释一下为什么会导致这样的错误?
【问题讨论】:
-
我相信您有身份验证问题。您需要配置 crontab 以使用例如 SSL 身份验证
-
我认为您在 cron 中运行的命令与您在命令行中所做的用户不同,因此存在身份验证问题。要么在同一用户下运行 cron 中的命令,要么为 cron 用户配置 ssh 密钥。
标签: git ubuntu github cron git-fetch