在Jenkins中管理Git的SSH密钥 [英] Managing SSH keys within Jenkins for Git

查看:3731
本文介绍了在Jenkins中管理Git的SSH密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Jenkins启动并运行一个GitHub托管的存储库(使用Jenkins Git插件)。存储库有多个git子模块,所以我不确定我想尝试和管理多个部署密钥。



我的个人GitHub用户帐户是每个项目我希望加入与Jenkins,所以我生成了一个SSH密钥在 /var/lib/jenkins/.ssh 并添加到我个人的GitHub帐户。 / p>

但是,当我尝试并添加存储库URL到我的Jenkins项目配置,我得到:

 无法连接到存储库:命令git ls-remote -h git@github.com:*** / ***。git HEAD返回的状态代码128:
stdout:
stderr:主机密钥验证失败。
fatal:远程结束意外挂起

同样, :

  stderr:主机密钥验证失败。 
fatal:远程端意外挂起

我也试过设置SSH配置文件,此处,但是没有效果。



任何人都可以照亮任何灯光?感谢



编辑



我应该补充说,我运行的是CentOS 5.8

解决方案

看起来像jenkins尝试连接的 github.com 未列在Jenkins用户的 $ HOME / .ssh / known_hosts 下。 Jenkins在大多数发行版上运行的用户 jenkins ,因此有自己的 .ssh 目录来存储公钥列表和 known_hosts



我能想到的解决这个问题的最简单的解决方案是:



#作为jenkins用户登录并指定shell显式
#因为默认shell是/ bin / false大多数
# jenkins安装。
sudo su jenkins -s / bin / bash

cd SOME_TMP_DIR
#git clone YOUR_GITHUB_URL

#允许将SSH主机密钥添加到您的known_hosts

#退出su
退出


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.

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.

However, when I try and add the repository URL to my Jenkins project configuration, I get:

Failed to connect to repository : Command "git ls-remote -h git@github.com:***/***.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.

Can anyone shed any light? Thanks

EDIT

I should add that I'm running CentOS 5.8

解决方案

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.

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

这篇关于在Jenkins中管理Git的SSH密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆