Jenkins SSH Key Management for Git

I am trying to start Jenkins using the GitHub repository (using the Jenkins Git plugin). There are several Git submodules in the repository, so I'm not sure I want to try a few deployment commands.

My personal GitHub account is a co-author of each of the projects that I want to use with Jenkins, so I created an SSH key in /var/lib/jenkins/.ssh and added it to my personal GitHub account.

However, when I try to add the repository URL to my Jenkins project configuration, I get:

 Failed to connect to repository : Command "git ls-remote -h git@github.com:***/***.git HEAD" returned status code 128: stdout: stderr: Host key verification failed. fatal: The remote end hung up unexpectedly 

Similarly, when I plan to build, I get:

 stderr: Host key verification failed. fatal: The remote end hung up unexpectedly 

I also tried setting up the SSH configuration file as described here , but to no avail.

Can anyone shed some light? Thanks

EDIT

I have to add that I am running CentOS 5.8

+47
git ssh continuous-integration jenkins
Mar 09 '13 at 19:11
source share
4 answers

It looks like the github.com host that jenkins is trying to connect to is not listed under Jenkins user $HOME/.ssh/known_hosts . Jenkins runs on most distributions as a jenkins user jenkins and therefore has its own .ssh for storing a list of public keys and known_hosts .

The easiest solution I can solve to solve this problem:

 # 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 
+60
Mar 09 '13 at 19:27
source share

Have you tried logging in as a jenkins user?

Try the following:

 sudo -i -u jenkins #For RedHat you might have to do 'su' instead. git clone git@github.com:your/repo.git 

Often you see a failure if the host has not been added or authorized (so I always manually enter as hudson / jenkins for the first connection to github / bitbucket), but this link that you included presumably fixes.

If the above does not work, try reinstalling the key. Make sure you have the pub key (i.e. id_rsa.pub). Maybe you missed a few characters?

+6
Mar 09 '13 at 19:26
source share

According to this article, you can try to run the following command:

  ssh-add -l 

If your key is not listed, then

  ssh-add /var/lib/jenkins/.ssh/id_rsa_project 
+4
Mar 09 '13 at 19:34
source share

This works for me, if you have a config and private key file in /Jenkins/.ssh/, you need to chown (change ownership) for these 2 files, then restart jenkins so that the jenkins instance can read these 2 files.

+1
Apr 15 '14 at 5:24
source share



All Articles