使用cron作业推送到GitHub - 权限被拒绝(publickey)

时间:2014-10-08 17:43:51

标签: git ubuntu ssh cron

我创建了一个SSH密钥(在the official tutorial之后),将其添加到GitHub并创建了一个Bash脚本,该脚本将单个文件提交并推送到Github上的我的存储库。当我从命令行运行此脚本时,一切正常,并推送更新。但是,当我使用crontab -e设置作业时,推送会生成以下错误:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

我已经修改了用户的crontab(crontab -e),即我没有使用sudo crontab -e。我正在运行Ubuntu 12.04。

1 个答案:

答案 0 :(得分:4)

如果它不是用户问题(以root身份运行作业,缺少正确的$ HOME / .ssh文件夹),则可以是passphrase issue

  

事实证明我错了,ssh密钥受密码保护(使用keychain加载ssh-agent),因此它从脚本失败但从bash会话运行时没有失败。
  将. ~/.keychain/$HOSTNAME-sh添加到我的脚本可以解决问题。

密码短语位在“Not able to ssh in to remote machine using shell script in Crontab”中详细说明:

  

您可以在cron会话中建立ssh连接。您需要的是设置公钥认证以进行无密码访问   为此,您需要在每个远程服务器的PubkeyAuthentication yes中使用sshd_config