我创建了一个 SSH key (在 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。
最佳答案
如果不是用户问题(您以 root 身份运行作业,缺少正确的 $HOME/.ssh 文件夹),它可能是 passphrase issue :
turns out I was mistaken, and the ssh key was password protected (with keychain loading the ssh-agent), hence why it failed from a script but not when running from the bash session.
Adding. ~/.keychain/$HOSTNAME-sh
to my script resolved the problem.
密码位在“Not able to ssh in to remote machine using shell script in Crontab”中有详细说明:
You can make ssh connections within a cron session. What you need is to setup a public key authentication to have passwordless access.
For this to work, you need to havePubkeyAuthentication yes
in each remote server'ssshd_config
.
关于git - 使用 cron 作业推送到 GitHub——权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26263128/