本文介绍了cron git push 与 ssh 密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为github账号设置了ssh key,所以不用每次都输入密码,效果很好.这是我使用的脚本:

I setup a ssh key for github account, so I don't have to enter the password every time, it works fine. Here is the script I use:

#!/bin/bash
git push origin master

但是当我使用 cron 运行它时,它不会使用我的 ssh 密钥.这是输出:

But when I use cron to run it, it will not use my ssh key. Here is the output:

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

我四处搜索并找到了一些文章,但没有一篇能解决我的问题.以下是我找到的文章(以及更多):

I search around and found some articles, but none of them solve my problem. Here are the articles I found(and a lot more):

https://askubuntu.com/questions/110565/why-is-git-not-using-my-pubkey-with-crontab

https://unix.stackexchange.com/questions/35466/how-to-perform-git-push-using-crontab

git push 通过 cron

谁能给我一步一步的说明来解决这个问题?

Can anybody give me a step to step instructions to solve this problem?

推荐答案

您的主题之一所述,您需要将执行您的 cron 脚本的 root 用户指向正确的 HOME(包含 $HOME/.ssh/id_rsa(.pub) 的那个,您的公共和私人键.

As mentioned in one of your thread, you need to point the root user which executes your cron script to the right HOME (the one which contains $HOME/.ssh/id_rsa(.pub), your public and private keys.

#!/bin/bash
HOME=/home/yourAccount git push origin master

如果这不起作用,请使用

If that doesn't work, start debugging your ssh command with

#!/bin/bash
HOME=/home/yourAccount ssh -Tvvv yourGitServer

并首先使用一个简单的私钥(不受密码保护)进行检查.
然后,如果您需要密码,请确保您的 ssh-agent 正在运行 为了缓存所述密码(或使用钥匙串,正如我之前提到的).

And check that with first a simple private key (not protected by a passphrase).
Then, if you need a passphrase, make sure your ssh-agent is running in order to cache said passphrase (or using keychain, as I mentioned before).

根据您的日志,建议使用公共 ssh 密钥,但被拒绝.

According to your logs, the public ssh key is proposed, but rejected.

debug1: Trying private key: /home/jack/.ssh/id_rsa
debug3: no such identity: /home/jack/.ssh/id_rsa

仔细检查BitBucket 为 Git 设置 SSH",并确保您的 id_rsaid_rsa.pub 在那里,有正确的保护.

Double-check "BitBucket Set up SSH for Git", and make sure your id_rsa and id_rsa.pub are there, with the right protection.

还要检查您的 id_rsa.pub 是否已添加到您的 BitBucket 帐户(作为一行).

Check also your id_rsa.pub has been added to your BitBucket account (as one line).

这篇关于cron git push 与 ssh 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:54
查看更多