5

I've setup Jenkins to pull from a private repository on Github for a specific job. It appears the SSH key is not being used by Jenkins, despite the fact that I have generated a private/public key and added it to github as a deploy key.

When I git clone from the Jenkins user, I'm prompted for a username and password. Why isn't it using my ~/.ssh/id_rsa.pub key?

Thanks

Kyle
  • 355
  • 1
  • 4
  • 13
  • 1
    I've seen problems like this when I wrongly assumed the Jenkins home directory was /home/jenkins rather than checking what it really was (/var/lib/jenkins), but it really does depend a lot on how you installed it, and how you've got it configured. Also, double check your permissions – Andrew Walker Jun 16 '12 at 23:34

2 Answers2

3

Which url are you using? It sounds like you are using the https one instead of the ssh one.

At the top of your projects github page, there are buttons for three urls, HTTP, SSH, Git read-only. You want the SSH one.

recampbell
  • 1,247
  • 8
  • 14
3

Just had the same problem, here is what you can do :

1) Login as jenkins users

sudo su jenkins

2) Generate keys for the jenkins user :

ssh-keygen -t rsa

3) Enter the id_rsa.pub as deploy key in the admin section of your repo on GitHub

Or even better :

  • Create a Github user for jenkins
  • Add the ssh key in the user profile information
  • Add the jenkins guthub user as a collaborator on your project

Hope this helps, Vincent

vdaubry
  • 11,369
  • 7
  • 54
  • 76
  • If you prefer not to add another user, you can go into your main account settings and add the key that way – Omertron Jan 28 '13 at 10:44
  • Also, you may need to get known_hosts on the jenkins box. To do that, enable the jenkins account (/etc/passwd) and git clone to accept the github/bitbucket pubkey – Cmag Aug 19 '15 at 16:08