小编典典

在Jenkins for Git中管理SSH密钥

jenkins

我正在尝试使用GitHub托管存储库(使用Jenkins
Git插件)启动Jenkins并使其运行。该存储库具有多个git子模块,因此我不确定我是否想尝试和管理多个部署密钥。

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

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

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

同样,当我计划构建时,我得到:

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

我也尝试过按此处概述的步骤设置SSH配置文件,但无济于事。

谁能阐明任何想法?谢谢

编辑

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


阅读 496

收藏
2020-07-25

共1个答案

小编典典

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

我可以想到的最简单的解决方案是:

# 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
2020-07-25