Managing SSH keys within Jenkins for Git

James picture James · Mar 9, 2013 · Viewed 139.8k times · Source

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 [email protected]:***/***.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

Answer

Tuxdude picture Tuxdude · Mar 9, 2013

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