在 Jenkins for Git 中管理 SSH 密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15314760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Managing SSH keys within Jenkins for Git
提问by James
I'm trying to get Jenkins up and running with a GitHub hosted repository (using the Jenkins Git plugin). The repository has multiple git submodules, so I'm not sure I want to try and manage multiple deploy keys.
我正在尝试使用 GitHub 托管存储库(使用 Jenkins Git 插件)启动并运行 Jenkins。存储库有多个 git 子模块,所以我不确定我想尝试管理多个部署密钥。
My personal GitHub user account is a collaborator of each of the projects I wish to pull in with Jenkins, so I've generated an SSH key within /var/lib/jenkins/.ssh
and added it to my personal GitHub account.
我的个人 GitHub 用户帐户是我希望与 Jenkins 合作的每个项目的合作者,因此我在其中生成了一个 SSH 密钥/var/lib/jenkins/.ssh
并将其添加到我的个人 GitHub 帐户中。
However, when I try and add the repository URL to my Jenkins project configuration, I get:
但是,当我尝试将存储库 URL 添加到我的 Jenkins 项目配置时,我得到:
Failed to connect to repository : Command "git ls-remote -h [email protected]:***/***.git HEAD" returned status code 128:
stdout:
stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly
Likewise, when I schedule a build I get:
同样,当我安排构建时,我会得到:
stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly
I've also tried setting up an SSH config file as outlined here, but to no avail.
我还尝试按照此处概述的方式设置 SSH 配置文件,但无济于事。
Can anyone shed any light? Thanks
任何人都可以发光吗?谢谢
EDIT
编辑
I should add that I'm running CentOS 5.8
我应该补充一点,我正在运行 CentOS 5.8
回答by Tuxdude
It looks like the github.com
host which jenkins tries to connect to is not listed under the Jenkins user's $HOME/.ssh/known_hosts
. Jenkins runs on most distros as the user jenkins
and hence has its own .ssh
directory to store the list of public keys and known_hosts
.
看起来github.com
jenkins 尝试连接的主机没有列在 Jenkins 用户的$HOME/.ssh/known_hosts
. Jenkins 以用户身份在大多数发行版上运行jenkins
,因此有自己的.ssh
目录来存储公钥和known_hosts
.
The easiest solution I can think of to fix this problem is:
我能想到的解决这个问题的最简单的方法是:
# Login as the jenkins user and specify shell explicity,
# since the default shell is /bin/false for most
# jenkins installations.
sudo su jenkins -s /bin/bash
cd SOME_TMP_DIR
# git clone YOUR_GITHUB_URL
# Allow adding the SSH host key to your known_hosts
# Exit from su
exit
回答by Adam Gent
Have you tried logging in as the jenkins user?
您是否尝试以 jenkins 用户身份登录?
Try this:
尝试这个:
sudo -i -u jenkins #For RedHat you might have to do 'su' instead.
git clone [email protected]:your/repo.git
Often times you see failure if the host has not been added or authorized (hence I always manually login as hudson/jenkins for the first connection to github/bitbucket) but that link you included supposedly fixes that.
如果主机没有被添加或授权,你经常会看到失败(因此,我总是以 hudson/jenkins 的身份手动登录以第一次连接到 github/bitbucket),但你包含的链接据说可以解决这个问题。
If the above doesn't work try recopying the key. Make sure its the pub key (ie id_rsa.pub). Maybe you missed some characters?
如果上述方法不起作用,请尝试重新复制密钥。确保它的 pub 密钥(即 id_rsa.pub)。也许你错过了一些角色?
回答by RabitChang
回答by Jianhong
This works for me if you have config and the private key file in the /Jenkins/.ssh/you need to chown(change owner) for these 2 files then restartjenkins in order for the jenkins instance to read these 2 files.
如果您在/Jenkins/.ssh/ 中有配置和私钥文件,这对我有用,您需要为这 2 个文件chown(更改所有者)然后重新启动jenkins,以便 jenkins 实例读取这 2 个文件。