【问题标题】:Jenkins - Unable to git clone from slave node. SSH keysJenkins - 无法从从节点克隆。 SSH 密钥
【发布时间】:2012-04-17 20:44:02
【问题描述】:

我刚刚设置了我的第一个 Jenkins 从站。我运行构建,但遇到了 SSH 密钥问题。 主 Jenkins 服务器在用户“jenkins”下运行。我已经设置了 SSH 密钥,这样我就可以在没有密码的情况下从主机 SSH 到从机。

例如来自主人:

jenkins@master:~$ ssh slave
Last login: Tue Apr 17 10:30:22 2012 from masterjenkins.com
$ whoami
jenkins

这样证明slave节点也在'jenkins'用户下运行。 (我已将公共 ssh 密钥从 jenkins@slave 复制到远程 git 服务器)。而且我可以从从站手动发出 git clone,但是当我从主站开始构建时,我会收到以下类型的消息:

    ERROR: Error cloning remote repo 'origin' : Could not clone git@host:abc
hudson.plugins.git.GitException: Could not clone git@host:abc
Caused by: hudson.plugins.git.GitException: Error performing command: git clone --progress -o origin git@host:abc /var/lib/jenkins/workspace/abc_build
Command "git clone --progress -o origin git@host:abc /var/lib/jenkins/workspace/abc_build" returned status code 128: Initialized empty Git repository in /var/lib/jenkins/workspace/abc_build/.git/
Host key verification failed.
fatal: The remote end hung up unexpectedly
Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin git@host:abc /var/lib/jenkins/workspace/abc_build" returned status code 128: Initialized empty Git repository in /var/lib/jenkins/workspace/abc_build/.git/
Host key verification failed.
fatal: The remote end hung up unexpectedly
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone

所以它仍然暗示我的 SSH 密钥设置不正确。 谁能告诉我需要将哪些密钥复制到哪里?

非常感谢, ns

【问题讨论】:

  • 主机密钥验证失败似乎表明您的 Jenkins 用户从未 ssh 进入该服务器并且您尚未接受主机密钥,请尝试以 jenkins 用户身份从 CLI 进行 ssh 以确保它可以工作,并接受主机密钥。
  • @Doon 这可能最终成为问题。我原本以为你正试图从 Jenkins 试图克隆的同一台机器上进行 ssh。
  • 搞定这个混蛋!感谢您的输入。我复制并粘贴了 jenkins 试图在从属设备上运行的命令: git clone --progress -o origin git@host:abc /var/lib/jenkins/workspace/abc 事实证明我在 /root 中有一些违规键/.ssh/known_hosts 删除这些并再次连接到 git repo 后,它工作了!

标签: git ssh hudson jenkins slave


【解决方案1】:

根据克隆 URL,您似乎混合了两种不同的身份验证方法。您正在尝试以用户 git 而不是 jenkins 的身份通过 SSH 连接到主机。通常,当您托管自己的 GIT 存储库并使用 git@servername:reponame 进行克隆时,您会使用 gitolite 之类的东西。

你有没有设置过类似 gitolite 的东西?

以 jenkins 用户身份尝试像这样 ssh'ing。

ssh git@slave 

然后看看返回什么。这是一个更符合您正在做的git@host:abc 的 SSH。

如果您没有在服务器机器上设置任何其他内容,请将您的克隆 URL 更改为 jenkins@host:pathtorepo

更新

/home/git/.ssh/authorized_keys

应该有这样的条目:(这都在一行上)

# gitolite start
command="/home/git/bin/gl-auth-command jenkins",no
-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAt3+od84Gc9NBVrVb3MKjekHcBDwXXONnVYMNVpuRadoz/FPJTkOIxozKVPJDPI670O252giYpF59sOKqAJL0xEVUrhq8cDFuFwQsSAp0ed1kp/GRxx+pwytL58rcVJEHAy2DkD1z5HlNaZyvIxQyfLTnYfuL1Hx6Qe7dal7mXO0= keycomment
# gitolite end

在 gitolite 中为 jenkins 添加存储库权限: (作为 gitolite 用户,您可能必须在托管存储库的同一台机器上进行克隆)

git clone git@host:gitolite-admin 
cd gitolite-admin
cd conf
vi gitolite.conf

现在找到'abc'的条目,如果不存在则添加一个

repo    abc
  RW+            = jenkins

现在提交并推送更改

git commit -a -m "Adding user jenkins to repo abc"
git push

现在再次发送ssh git@host 以查看 gitolite 是否告诉您有关您的新权限。

【讨论】:

  • 嗨,对不起,是的,我忘了补充一点,我们使用 gitolite 来管理我们的 git 用户。作为 ssh git@slave 从主服务器到从服务器的 ssh 只是提示输入密码。困扰我的一件事是,我无法轻易找到一种简单的方法来查看詹金斯在奴隶上的运行情况。登录到从站后,我执行了 ssh-keygen 并将文件保存在默认位置,即 /home/jenkins/.ssh/id_rsa。然后我将公钥复制到 gitolite。
  • @nonshatter 这意味着 gitolite 或其他东西没有正确设置。您确定您的服务器上已正确设置了 authorized_keys 吗?我使用 gitlab 来管理我的 gitolite 实例。在您无需密码即可成功 ssh git@host 之前,您的克隆将无法工作。首先要检查的是服务器上git 用户的authorized_keys 和您的jenkins 名称以及正确的公钥。
  • 来自从站:$ ssh git@host PTY allocation request failed on channel 0 hello jenkins, this is gitolite v2.1-31-gf0cedeb running on git 1.7.0.4 the gitolite config gives you the following access: @R_ @W_ testing R W abc Connection to host closed.
  • @nonshatter 是您尝试从 Jenkins 克隆的名为“测试”的存储库名称吗?
  • @nonshatter,“困扰我的一件事是,我无法轻易找到一种简单的方法来查看 jenkins 在奴隶上的运行情况” - 一种方法是创造一份工作附加到在 shell 构建步骤中运行 whoami 的从站。
猜你喜欢
  • 1970-01-01
  • 2019-05-28
  • 2021-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-24
  • 2020-06-03
  • 1970-01-01
相关资源
最近更新 更多