1

I have generated a pubic SSH key on my Ubuntu 20.04 server with the user Jenkins, and my key is stored below :

/var/lib/jenkins/.ssh/id_rsa.pub

I have set that public Key on my Gitlab SSH parameters, And I had also create a Credentials in Jenkins for SSH Private key, where i pasted the private key i had generate for my Jenkin's user in linux 20.04 remote server. When i try to clone the projet using SSH, i get the error :

Failed to connect to repository : Error performing git command: /usr/lib/git-core ls-remote -h git@gitlab.com:project/repository.git HEAD*

Need a helping hand to solve this problem. enter image description here

1 Answers1

0

First, check that your key is indeed considered when doing ssh with the jenkins account:

ssh -Tv git@gitlab.com

You will see where SSH is looking for your keys, and if /var/lib/jenkins/.ssh/id_rsa is used.
You should see a welcome message.

Second, Check the Jenkins logs to see if there is any additional clues.

You might need to use an SSH key using the old PEM format:

ssh-keygen -m PEM -t rsa -P "" -f afile 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I Try to this command ssh -Tv git@gitlab.com and I saw the welcome message, But no Log on Jenkins was recorded – Boubacar Fofana May 05 '21 at 13:55
  • @BoubacarFofana in command-line, can you check if `git ls-remote git@gitlab.com:project/repository.git` works? (replacing project and repository by the right names) – VonC May 05 '21 at 14:36
  • yes it worked here is the result `41cf42a0784a refs/heads/dev 8a5e73286edb2feba89f15d2b656b55d9e49bdac refs/heads/main db1665aca17037954d2ff659093c24c0e1e1170a refs/heads/master 77abc7c7c1d9fa2cc4eb92b7c314cd00dcae326a refs/merge-requests/10/head 55d54746fdfeb1c777044809e43892287d80002e refs/merge-requests/10/merge 58624e027802daf0326aded7779f1b14bd3345e7 refs/merge-requests/11/head 83c373fb42d246949f7f467bab34d3accc736bc2 refs/merge-requests/11/merge e198cc411df8c68230e6509c5311114fd94af835 refs/merge-requests/9/head ` – Boubacar Fofana May 06 '21 at 02:35
  • @BoubacarFofana Can you try again, this time with an SSH key using the old PEM format, as described in https://stackoverflow.com/a/53645530/6309? Check that new key also work in command line, then use this new private key in your Jenkins credentials and see if the job definition works. – VonC May 06 '21 at 06:49
  • Hi I tried again but it didnt work. I decided use the jenkins container and i had the same issue. When I try to use public repository from GitLab ou Github, everything goes fine. When it's about a private repository it failed. – Boubacar Fofana May 07 '21 at 15:27
  • @BoubacarFofana And that same access to private repo works from command line? – VonC May 07 '21 at 15:29
  • From command line yes. It Worked and i have a welcome message to my Git account – Boubacar Fofana May 07 '21 at 15:31
  • @BoubacarFofana Strange: if the private key (especially in the old format) is recorded in the Jenkins credentials, it should work. – VonC May 07 '21 at 15:32
  • as i use Docker now I have the same issue. Im still using the old format of the private key and i have `Failed to connect to repository : Error performing git command: ls-remote -h git@gitlab.com:project xxx HEAD` – Boubacar Fofana May 08 '21 at 03:07
  • @BoubacarFofana Can you `export GIT_SSH_COMMAND='ssh -Tv` first, then try again? That should show you where git is looking for its keys. – VonC May 08 '21 at 10:46
  • can you please explain Step By Step how should i do the following command `$GIT_SSH_COMMAND` because nothing happened in my terminal want type `export GIT_SSH_COMMAND='ssh -Tv' ` – Boubacar Fofana May 10 '21 at 00:57
  • @BoubacarFofana I meant stop Jenkins, type the `export` command, as the `jenkins` account, and restart Jenkins. That way, you will see more details in Jenkins logs. – VonC May 10 '21 at 06:53