Jenkins 失败,错误代码为 : Host key verification failed

标签 jenkins bitbucket ssh-keys

我在 Macbook Pro(操作系统:Mountain Lion)上下载并安装了 Mac OSX 版 Jenkins。我现在想要将其设置为从 bitbucket 中拉取项目并进行自动构建。

我创建了 ssh key ,将其添加到 bitbucket 并尝试设置构建作业。但是,我收到错误:

无法连接到存储库:命令“git ls-remote -h HEAD”返回状态代码 128: 标准输出: stderr:主机 key 验证失败。 fatal:远端意外挂断

我尝试从known_hosts 中删除导致问题的域,但仍然收到此错误。

请指教。

最佳答案

我想我在这篇文章中找到了可能的解决方案:http://colonelpanic.net/2011/06/jenkins-on-mac-os-x-git-w-ssh-public-key/

Jenkins on Mac OS X I just finished setting up a build server on Mac OS X using Jenkins (formerly Hudson). The company I’m working for (GradeCam) uses git and gitolite for our source control and so I expected no trouble using Jenkins to build our tools using the git plugin.

However, I quickly ran into a snag: the source control server is on a public address and so our source code is not available except via ssh, and gitolite ssh access uses private key authentication. Well, I’m an experience unix sysadmin, so that didn’t sound like a big issue — after all, setting up public key authentication is childs play, right?

Default install

The default installation of Jenkins on Mac OS X (at the time of this writing) installs a Launch Agent plist to /Library/LaunchAgents/org.jenkins-ci.plist. This plist file causes Jenkins to load as user “daemon”, which sounds fine — except that the home directory for the “daemon” user is /var/root, same as for user root. This means that the .ssh dir in there will never have the right permissions for a private key to be used.

Creating a new hidden user

My solution was to create a new “hidden” user for Jenkins to run under. Following instructions I found on a blog post, I created a user “jenkins” with a home directory “/Users/Shared/Jenkins/Home”:

sudo dscl . create /Users/jenkins
sudo dscl . create /Users/jenkins PrimaryGroupID 1
sudo dscl . create /Users/jenkins UniqueID 300   
sudo dscl . create /Users/jenkins UserShell /bin/bash
sudo dscl . passwd /Users/jenkins $PASSWORD
sudo dscl . create /Users/jenkins home /Users/Shared/Jenkins/Home/

I then stopped Jenkins: “sudo launchctl unload -w /Library/LaunchAgents/org.jenkins-ci.plist” and edited the plist file to set the username to jenkins instead of daemon.

“chown -R jenkins: /Users/Shared/Jenkins/Home”

sets the permissions how they need to be, and then “sudo launchctl load -w /Library/LaunchAgents/org.jenkins-ci.plist” should get you up and running!

To get git over ssh running, “sudo su – jenkins” to get a console as the jenkins user and set up the ssh keys and such. Make sure you can ssh to where you want to go (or even do a test git clone) because you need to save the keys so it doesn’t ask for them when jenkins tries to do the clone.

That should do you! Hope it helps someone.

关于Jenkins 失败,错误代码为 : Host key verification failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138662/

相关文章:

jenkins - 如何使用 Jenkins DSL 设置作业超时

git - 我怎么能强制从prod用户提交--author <the_real_author>

docker - stdin不是 Jenkins 的tty

docker - Jenkins Docker管道插件引用了旧的JENKINS_HOME

Git 推送到登台服务器

git - Bitbucket - 我可以跟踪或查看谁从存储库中克隆或提取数据吗?

ssh - 如何通过ssh从一个ec2实例连接到另一个ec2实例

macos - 在不同的 Mac 上使用 SSH key

Git pull 和推不起作用

Angular 5 : Karma Unit testing fails to start HeadlessChrome on CI environment