Permission denied (public key) during fetch from G

2020-05-20 07:36发布

Here is my setup:

  1. Jenkins is running on my linux machine as 'jenkins' user.
  2. I have generated a ssh key-pair as described in Linux - Setup Git, for the 'jenkins' user.
  3. When I sudo su jenkins and try ssh -vT git@github.com, I am always asked my passphrase, but I am always eventually authenicated. (the verbose option shows which key is used, among others).
  4. I could clone my repo from GitHub using jenkins:

Thusly:

jenkins@alpm:~/jobs/test git/workspace$ git pull 
Enter passphrase for key '/var/lib/jenkins/.ssh/id*_rsa':
Already up-to-date.

Up to this point I have followed the instructions to the letter. The problem is that the Jenkins job fails with the following error:

status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedly

This is same error as I get when I typo the passphrase (but of course, Jenkins does not ask me for the passphrase). The following pages:

indicate to me that ssh-agent could help remember the passphrase, which it does when I am using my own user, but not the jenkins id. Note that while running as my normal user yields:

echo "$SSH_AUTH_SOCK"
/tmp/keyring-nQlwf9/ssh

While running the same command as my 'jenkins' yields nothing (not even permission denied)

My understanding of the problem is that the passphrase is not remembered. Do you have any idea? Shall I start a ssh-agent or key ring manager for the jenkins user? How? Or is ssh forwarding suitable when forwarding to the same machine? Any brighter idea?

ps: I never sudo gitted, I always used jenkins or my user account (as mentioned in this SO post - Ubuntu/GitHub SSH Key Issue)

8条回答
Evening l夕情丶
2楼-- · 2020-05-20 08:12

If you are running jenkins as a service in windows, you need to verify the user running the service. If you created the keys using the user "MACHINENAME\user", change the service so the user running it can match

查看更多
forever°为你锁心
3楼-- · 2020-05-20 08:17

I would add that if you created the keys by hand, they might still be owned by you and not readable by jenkins, try:

sudo chown jenkins -R /var/lib/jenkins/.ssh/*
查看更多
登录 后发表回答