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,700 points
62,179 views

5 answers to this question.

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
• 10,620 points
It shows permission denied.
Add your public key to the repository at bitbucket.org

issue is with the /var/lib/jenkins/.ssh/known_hosts. It exists in the first case, but not in the second one. This means you are running either on different system or the second case is somehow jailed in chroot or by other means separated from the rest of the filesystem (this is a good idea for running random code from jenkins).

Next steps are finding out how are the chroots for this user created and modify the known hosts inside this chroot. Or just go other ways of ignoring known hosts, such as ssh-keyscan, StrictHostKeyChecking=no or so.

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/id_rsa.pub

5) Copy key from id_rsa.pub

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
• 7,060 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 id_rsa.pub
-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 git@bitbucket.org:user/project.git HEAD
answered Aug 13, 2018 by lina
• 8,220 points
0 votes

Set git path to your git executable

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

answered Apr 23, 2019 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 git@github.com:adolfosrs/jenkins-test.git 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, 2019 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,220 points
7,488 views
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
• 10,620 points
3,593 views
+2 votes
5 answers
0 votes
2 answers

Error Jenkins: Failed to connect to repository

Jenkins runs as another user, not as ...READ MORE

answered Aug 7, 2019 in Jenkins by Sirajul
• 59,230 points
10,671 views
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,680 points
1,387 views
+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
4,059 views
+2 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP