How to resolve this error “Jenkins Host key verification failed”?

0 votes

I’m facing a problem with Jenkins while setting "git". I get the following error:

Failed to connect to repository : Command "git ls-remote -h http://github/someone/gittest.git HEAD" 
stderr: fatal: Authentication failed
Jul 23, 2018 in Jenkins by Tyrion anex
• 8,280 points

5 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

This is quite simple, so first you have to change to the Jenkins user and execute the following command :

git ls-remote -h ‘repo URL’ HEAD

After this, you will get a SSH warning. This happens when you first connect to a new host via SSH:

The authenticity of host 'github/someone/git.git' can't be established.
Are you sure you want to continue connecting (yes/no)?

Type yes and press Enter. The host key will be added to the ~/.ssh/known_hosts file and you won't face this error henceforth.

answered Jul 23, 2018 by Sophie may
• 9,050 points
It shows permission denied.
Add your public key to the repository at
0 votes

1)Execute following commands on terminal 

  $ sudo su -s /bin/bash jenkins

provide password

2)Generate public private key using the following command:

$ ssh-keygen

you can see output as ::

Generating public/private rsa key pair. 
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

3)Press Enter --> Do not give any passphrase--> press enter 

  Key has been generated

4) go to --> cat /var/lib/jenkins/.ssh/

5) Copy key from

6)Exit from bash

7) ssh@yourrepository

8) vi .ssh/authorized_keys

9) Paste the key

10) exit

11)Manually login to mercurial server

12)once manually done, Now go to Jenkins and give build

answered Aug 10, 2018 by Nilesh
• 6,900 points
0 votes

I had the same problem. Try this, it worked for me:

reset permission on id_rsa* only for current user no group no other

chmod o-rwx ~/.ssh/id*
chmod G-rwx ~/.ssh/id*
ls -lart ~/.ssh/
-rw-------  1 jenkins nogroup  398 avril  3 09:34
-rw-------  1 jenkins nogroup 1675 avril  3 09:34 id_rsa
And clear ~/.ssh/know_hosts

Now Connect as jenkins

sudo su jenkins

Try the jenkins commands

git ls-remote -h HEAD
answered Aug 13, 2018 by lina
• 8,100 points
0 votes

Set git path to your git executable

Manage Jenkins => Configure System => Git => Git Installations => Path to Git executable.

answered Apr 23 by Vinay
How do I get the git executable path?
+2 votes
HI Mam,

Please check the following solution::

1. Switch to jenkins user (sudo -iu jenkins)

2. Run: ssh-keygen (Note - You are creating ssh key pairs for jenkins user now. You should see something like this : Enter file in which to save the key (/Users/Shared/Jenkins/.ssh/id_rsa):

3. Keep pressing Enter for default value till end

4. Run the command showing in the Jenkins error message, on your terminal (eg : "git ls-remote -h HEAD")

5. You will be asked if you want to continue. Say yes

6. The Github repo will be added to your known_hosts file in : /Users/Shared/Jenkins/.ssh/

7. Go back to Jenkins portal and try your Github SSH url

It should work. Good Luck
answered May 3 by anonymous
Thanks a lot for such a nice explanation! I'll upvote your answer :)

Related Questions In Jenkins

0 votes
1 answer
0 votes
2 answers

How to solve this error “Jenkins - j_acegi_security_check” ?

This is how I resolved this issue: # ...READ MORE

answered Aug 13, 2018 in Jenkins by lina
• 8,100 points
0 votes
1 answer

I’m facing a login error when I try to run Jenkins on Docker. How do I solve this?

You have to open the /var/log/jenkins/jenkins.log file to ...READ MORE

answered Jul 24, 2018 in Jenkins by Sophie may
• 9,050 points
+2 votes
5 answers
0 votes
1 answer

Error Jenkins: Failed to connect to repository

This happens when you create the ssh ...READ MORE

answered Jul 6, 2018 in Jenkins by Sophie may
• 9,050 points
0 votes
1 answer

How do I pass value from my Fake # script to the host build server (Jenkins)

You can use the EnvInject plugin to pass environment ...READ MORE

answered Jul 11, 2018 in Jenkins by Kalgi
• 2,620 points
+13 votes
2 answers
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.