'Git | Jenkins | Permission denied (publickey)

We have a common LDAP account/user. We plan to use this user to configure Jenkins for our team.

  1. I logged in to the machine/VM using my login and installed Jenkins.
  2. Then I generated ssh keys from my account only but the email id I provided while generating ssh keys was the common user.
  3. Then I added the public ssh key to the GitHub (in Github I logged in using common user).
  4. Added the private key to Jenkins SSH credential plugin.
  5. Created a job that does poll SCM and it worked fine.
  6. I need to execute some git commands (i.e pull, checkout, tag etc...). Therefore, I'm writing ant scripts to achieve this.
  7. When I execute the GIT ant target [1] through Jenkins, I get the following error:

fetch: [echo] ---------------------------------------------------------

[echo] Fetching Latest from [email protected]:XYZ/ABC master

[echo] ---------------------------------------------------------

[exec] [email protected]: Permission denied (publickey).

[exec] fatal: Could not read from remote repository.

[exec]

[exec] Please make sure you have the correct access rights

[exec] and the repository exists.


Do I have to log in to the VM using common account/user and generate the ssh keys and then use those keys? If yes, then how come Point# 5 is working fine? If no, what is wrong I'm doing here?

[1] - Specify git commands in Jenkins Git plugin



Solution 1:[1]

Jenkins will use its private key associated with the job to read the remote repo.

But: the script executed within the job itself will use the default SSH key found in the user running Jenkins itself: ~user/.ssh/id_rsa

Make sure the default private key is the one you need for that job (or you can set one through ~/.ssh/config): the point being, this is no longer related to the Jenkins SSH Credential plugin.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC