# Jenkins not able to connect to git repository

**URL:** <https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707>\
**Category:** Community\
**Created:** [July 27, 2023, 12:05am UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707 "2023-07-27T00:05:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [July 27, 2023, 12:05am UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/1 "2023-07-27T00:05:57Z")

</div>

got error: Failed to connect to repository : Error performing git command: git ls-remote -h [git@mcdasatest07.isd.lacounty.gov](mailto:git@mcdasatest07.isd.lacounty.gov):jenkins/ampsoaapplication.git HEAD  
when connecting GitLab from Jenkins.

After installed GIT 2.32.0, got error:  
Failed to connect to repository: Command “git ls-remote -h [git@mcdasatest07.isd.lacounty.gov]:jenkins/ampsoaapplication.git HEAD” returned status code 128:  
stdout:  
stderr: Host key verification failed.  
fatal: Could not read from remote repository.  
Please make sure you have the correct access rights  
and the repository exists.

What’s the password for [git@mcdasatest07.isd.lacounty.gov](mailto:git@mcdasatest07.isd.lacounty.gov) supposed to be?

Thank you

Holly

---

<div class="post-metadata">

**Author:** ![aburdajewicz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/aburdajewicz/32/436_2.png) [@aburdajewicz](https://community.jenkins.io/u/aburdajewicz)\
**Post date:** [July 27, 2023, 2:10am UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/2 "2023-07-27T02:10:42Z")

</div>

Hi Holly,

This is a host key verification problem. You need to configure a strategy as documented in [GitHub - jenkinsci/git-client-plugin at git-client-4.0.0](https://github.com/jenkinsci/git-client-plugin/tree/git-client-4.0.0#ssh-host-key-verification).

Regards,

---

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [July 27, 2023, 3:08pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/3 "2023-07-27T15:08:42Z")

</div>

Thank you Allen. Does this document also good for GitLab? I am using GitLab. Thank you

- Holly

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [July 27, 2023, 3:43pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/4 "2023-07-27T15:43:14Z")

</div>

Yes, the documentation applies for GitLab and all other git providers. When the documentation is specific to a git provider, it will list the specific git providers.

Documentation is most easily read from the [plugins.jenkins.io/git-client page](https://plugins.jenkins.io/git-client/#plugin-content-ssh-host-key-verification)

> **[Git client](https://plugins.jenkins.io/git-client/#plugin-content-ssh-host-key-verification)**
>
> Utility plugin for Git support in Jenkins

---

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [July 28, 2023, 1:20am UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/5 "2023-07-28T01:20:29Z")

</div>

Thank you for the reply.  
reinstall Git, connecting to Git with Jenkins, got error:  
Failed to connect to repository : Error performing git command: git ls-remote -h [git@mcdasatest07.isd.lacounty.gov](mailto:git@mcdasatest07.isd.lacounty.gov):jenkins/ampsoaapplication.git HEAD

Follow instruction [git - “Failed to connect to repository” Error while setting up Github Jenkins Plugin - Stack Overflow](https://stackoverflow.com/questions/12681308/failed-to-connect-to-repository-error-while-setting-up-github-jenkins-plugin) **Manage Jenkins → Configure System → Git → Git Installations → Path to Git executable**.

couldn’t find Git session in Manage Jenkins → Configure System

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [July 28, 2023, 1:37am UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/6 "2023-07-28T01:37:21Z")

</div>

Do you have the git plugin(s) installed?

---

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [August 1, 2023, 5:40pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/7 "2023-08-01T17:40:45Z")

</div>

Thank you slide.  
Yes, I am able to find set up location.  
Allan/Mark - [plugins.jenkins.io/git-client page](https://plugins.jenkins.io/git-client/#plugin-content-ssh-host-key-verification), how could I use this document ? what strategy I can use to configure? My current set up by default Known hosts file.  
When I run command (git ls-remote -h [git@mcdasatest07.isd.lacounty.gov]:jenkins/ampsoaapplication.git HEAD) from server, it keep asking me the password and not recognized the password.

mcdasatest07:/var/cache\>git ls-remote -h [git@mcdasatest07.isd.lacounty.gov]:jenkins/ampsoaapplication.git  
[git@mcdasatest07.isd.lacounty.gov](mailto:git@mcdasatest07.isd.lacounty.gov)’s password:  
Permission denied, please try again.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [August 1, 2023, 6:06pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/8 "2023-08-01T18:06:19Z")

</div>

You might try this video tutorial from Darin Pope:

[![](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/e/e1dd4ebe451c4d693ecb4a08a2cb18431a01a3e8.jpeg "How to Add Git Credentials in Jenkins") ](https://www.youtube.com/watch?v=HSA_mZoADSw)

The message from command line git indicates that you’re either providing the wrong ssh private key credential or you’re providing a username / password credential instead of providing an ssh private key credential.

The git repository URL `git@mcdasatest07.isd.lacounty.gov]:jenkins/ampsoaapplication.git` is a URL that tells command line git to authenticate with `ssh` using an ssh private key. If you’ve not defined an ssh private key credential, then you need to do that. If you’ve defined a username / password credential instead of an ssh private key credential, then you need to change to use `https` instead of `ssh` for the git repository URL.

> [@hollychen](#):
>
> Allan/Mark - [plugins.jenkins.io/git-client page](https://plugins.jenkins.io/git-client/#plugin-content-ssh-host-key-verification), how could I use this document ? what strategy I can use to configure? My current set up by default Known hosts file.

Based on the message from `git ls-remote`, you don’t need to change the ssh host key verification strategy. It is already working as expected.

Your [original post](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/1) had this message:

> [@hollychen](#):
>
> Failed to connect to repository: Command “git ls-remote -h [git@mcdasatest07.isd.lacounty.gov]:jenkins/ampsoaapplication.git HEAD” returned status code 128:  
> stdout:  
> stderr: Host key verification failed.  
> fatal: Could not read from remote repository.

If you’re still seeing that message, then you need to adjust your host key verification strategy. The message `Host key verification failed` means that you do not have a working host key verification strategy because host key verification is failing.

---

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [August 1, 2023, 11:38pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/9 "2023-08-01T23:38:38Z")

</div>

Thanks Mark.

I created a SSH key for another application on my local. Do I need to create another SSH key for this application or I can share the same SSH key with that application.  
Is there any meeting discussion in our community? that will be a big help and speed up the issue resolve process.  
Appreciate your help.

---

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [August 2, 2023, 4:45pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/10 "2023-08-02T16:45:39Z")

</div>

I created a SSH key for another application on my local. Do I need to create another SSH key for this application or I can share the same SSH key with that application.  
Each application need to have it’s own git set up? Please advise.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [August 2, 2023, 4:59pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/11 "2023-08-02T16:59:02Z")

</div>

> [@hollychen](#):
>
> Do I need to create another SSH key for this application or I can share the same SSH key with that application.  
> Each application need to have it’s own git set up?

It is your choice whether you use the same ssh key or a separate ssh key.

The separate ssh key adds some management overhead (need to track it, etc.) but then allows that ssh key to be removed from the account or rotated without breaking any other use of that repository.

---

<div class="post-metadata">

**Author:** ![hollychen](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hollychen](https://community.jenkins.io/u/hollychen)\
**Post date:** [August 2, 2023, 10:54pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/12 "2023-08-02T22:54:14Z")

</div>

Issue resolved. Thank you.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [August 3, 2023, 4:56pm UTC](https://community.jenkins.io/t/jenkins-not-able-to-connect-to-git-repository/8707/13 "2023-08-03T16:56:34Z")

</div>

Thanks for your feedback @hollychen . 🙏
