git - 使用 cron 作业推送到 GitHub——权限被拒绝(公钥)

标签 git ubuntu ssh cron

我创建了一个 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 have PubkeyAuthentication yes in each remote server's sshd_config.

关于git - 使用 cron 作业推送到 GitHub——权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26263128/

相关文章:

git - 修改 "git add"之后的文件

git - 将 git 连接到 Github 帐户

linux - 系统上不存在 JDK,但系统表示需要将其删除

python-2.7 - 无法在 ITK 中加载 .mha 文件

mysql - 通过 SSH 使用 R (RMySQL) 连接 MySQL

git - key_load_public : No such file or directory even though file exists

git - 为什么 git 不忽略 Maven 目标文件夹中 surefire-reports\folder 的内容?

c++ - C/C++ 代码的等效 asm 代码

linux - 在 ubuntu 中自定义 ssh 命令

amazon-web-services - 通过 SSH 连接到 AWS 上的 ec2 实例