Jenkins - 无法从从节点进行 git clone。SSH 密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10190919/
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
Jenkins - Unable to git clone from slave node. SSH keys
提问by nonshatter
I have just set up my first Jenkins slave. I run the build, and I hit problems with the SSH keys. The master Jenkins server is running under the user 'jenkins'. I have set up the SSH keys such that I can SSH from the master to the slave without a password.
我刚刚建立了我的第一个 Jenkins slave。我运行构建,但遇到了 SSH 密钥问题。Jenkins 主服务器在用户“jenkins”下运行。我已经设置了 SSH 密钥,这样我就可以在没有密码的情况下从主站到从站进行 SSH 连接。
e.g. From the master:
例如来自主人:
jenkins@master:~$ ssh slave
Last login: Tue Apr 17 10:30:22 2012 from masterjenkins.com
$ whoami
jenkins
So that proves that the slave node is also running under the 'jenkins' user. (I have copied the public ssh key from the jenkins@slave to the remote git server). And I am able to issue the git clone manually from the slave, but when I kick off the build from the master I get these kinds of messages:
所以这证明从节点也在'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
So it is still hinting that my SSH keys are not set up correctly. Can anyone tell me what keys I need to copy where?
所以它仍然暗示我的 SSH 密钥设置不正确。谁能告诉我需要复制哪些密钥?
Many thanks, ns
非常感谢, ns
采纳答案by Andrew T Finnell
Based on the clone URL it appears you are mixing up two different authentication methods. You are trying to SSH into host as the user git
not jenkins
. Typically when you host your own GIT repositories and clone with git@servername:reponame you use something like gitolite.
根据克隆 URL,您似乎混合了两种不同的身份验证方法。您正在尝试使用SSH连接主机的用户git
没有jenkins
。通常,当您托管自己的 GIT 存储库并使用 git@servername:reponame 进行克隆时,您会使用类似 gitolite 的东西。
Did you set anything up like gitolite?
你有没有设置像gitolite这样的东西?
Try ssh'ing like this instead as the jenkins user.
以 jenkins 用户的身份尝试像这样 ssh'ing。
ssh git@slave
Then see what that returns. This is an SSH more in line with the git@host:abc
you are doing.
然后看看返回什么。这是一个更符合git@host:abc
你正在做的SSH 。
If you didnt setup anything else on your server machine, then change your clone url to jenkins@host:pathtorepo
如果您没有在服务器计算机上设置任何其他内容,请将您的克隆 url 更改为 jenkins@host:pathtorepo
Update
更新
/home/git/.ssh/authorized_keys
/home/git/.ssh/authorized_keys
Should have an entry like this: (This is all on ONE line)
应该有这样的条目:(这都在一行上)
# 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
Add repository permissions to jenkins in gitolite: (You may have to clone on the same machine that is hosting your repositories, as the gitolite user)
在 gitolite 中向 jenkins 添加存储库权限:(您可能必须在托管存储库的同一台机器上克隆,作为 gitolite 用户)
git clone git@host:gitolite-admin
cd gitolite-admin
cd conf
vi gitolite.conf
Now find the entry for 'abc' or add one if it doesn't exist
现在找到“abc”的条目,如果不存在则添加一个
repo abc
RW+ = jenkins
Now commit and push changes
现在提交并推送更改
git commit -a -m "Adding user jenkins to repo abc"
git push
Now do your ssh git@host
again to see if gitolite tells you about your new permissions.
现在再做ssh git@host
一次,看看 gitolite 是否告诉你你的新权限。