Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing SSH keys within Jenkins for Git

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

like image 874
James Avatar asked Mar 09 '13 19:03

James


People also ask

How does SSH key integrate with Jenkins and GitHub?

Configure SSH Key for GitHub Project Once logged in to GitHub, you need to go to the sample repository on which you have access. Go to repository settings -> Deploy keys -> Add deploy key: Give a name such as 'Jenkins User' and add the key. You may select 'allow write access' as well.


1 Answers

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 
like image 94
Tuxdude Avatar answered Sep 27 '22 21:09

Tuxdude