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

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

问题描述

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

我的个人 GitHub 用户帐户是我希望与 Jenkins 合作的每个项目的合作者,因此我在 /var/lib/jenkins/.ssh 中生成了一个 SSH 密钥,并且已将其添加到我的个人 GitHub 帐户中.

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

无法连接到存储库:命令git ls-remote -h git@github.com:***/***.git HEAD"返回状态代码 128:标准输出:stderr:主机密钥验证失败.致命:远端意外挂断

同样,当我安排构建时,我得到:

stderr:主机密钥验证失败.致命:远端意外挂断

我也试过设置一个 SSH 配置文件 此处,但无济于事.

任何人都可以发光吗?谢谢

编辑

我应该补充一点,我正在运行 CentOS 5.8

解决方案

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

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

# 以 jenkins 用户身份登录并明确指定 shell,# 因为大多数情况下默认 shell 是/bin/false#詹金斯安装.须藤 su jenkins -s/bin/bashcd 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天全站免登陆