Git | Jenkins | Permission denied (publickey)

旧时模样 提交于 2020-07-20 03:37:35

问题


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 git@github.XYZ.com:XYZ/ABC master

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

[exec] git@github.XYZ.com: 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


回答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.



来源:https://stackoverflow.com/questions/54301440/git-jenkins-permission-denied-publickey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!