Managing SSH keys within Jenkins for Git

0 votes

I'm trying to get Jenkins up and running with a GitHub hosted repository. I'm not sure I have to try and manage multiple deploy keys because The repository has multiple git submodules.

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***/***.git HEAD" returned status code 128:
stderr: Host key verification failed. 
fatal: The remote end hung up unexpectedly

Where am I going wrong?

Aug 9, 2018 in Jenkins by lina
• 8,220 points

2 answers to this question.

0 votes

The host which Jenkins tries to connect to is not listed under the Jenkins user's $HOME/.ssh/known_hosts. Jenkins has its own ssh directory to store the list of public keys and known hosts.

The easiest thing to do would be:

# 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
# git clone YOUR_GITHUB_URL
# Allow adding the SSH host key to your known_hosts
# Exit from su
answered Aug 9, 2018 by Kalgi
• 52,360 points
0 votes

Have you tried logging in as the jenkins user?

Try this:

sudo -i -u jenkins #For RedHat you might have to do 'su' instead.
git clone

Often times you see failure if the host has not been added or authorized (hence I always manually login as hudson/jenkins for the first connection to github/bitbucket) but that link you included supposedly fixes that.

If the above doesn't work try recopying the key. Make sure its the pub key (ie Maybe you missed some characters!

answered Aug 8, 2019 by Sirajul
• 59,230 points

Related Questions In Jenkins

0 votes
1 answer

Why is it displaying Jenkins build failure for Android app

I think you should try this. Try Uninstalling ...READ MORE

answered Apr 12, 2018 in Jenkins by shubham
• 7,340 points
0 votes
2 answers

Is possible for Jenkins to auto start and stop slave nodes?

Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

answered Aug 6, 2018 in Jenkins by Nilesh
• 7,050 points
0 votes
1 answer

Ansible or Jenkins pipelines for bigger jobs

Well, you are indeed well aware of ...READ MORE

answered Jun 17, 2018 in Jenkins by shubham
• 7,340 points
+1 vote
1 answer

Unable to access Jenkins. I newly installed Jenkins but for some reason I cannot access it.

Try changing the port, Change JENKINS_AJP_PORT="xyz" to JENKINS_AJP_PORT="abc" If changing the ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 10,610 points
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 votes
1 answer
+1 vote
3 answers
0 votes
2 answers

Jenkins Git plugin detached HEAD

Go to Job Configuration. Scroll down to ...READ MORE

answered Aug 13, 2018 in Jenkins by lina
• 8,220 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP