Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing github credentials for Jenkins

I am a new user to Jenkins, so please bear with me.

The employee who set up Jenkins for us quit and we removed his access to our github repo. But he had configured our automated build to access git as himself, so of course that is failing now. I went into the project settings and added a new credential for a user that does have access to our github repo, along with their github password, and I installed that user's ssh key to github. Now when the build runs I get this:

Permission denied (publickey).

What else do I have to do to switch the user that accesses our repo for builds? How can I see what it's getting "Permission denied" on?

like image 838
Larry Martell Avatar asked May 26 '26 12:05

Larry Martell


1 Answers

To setup a user's GitHub SSH key on Jenkins:

  1. Add your user's SSH key to the GitHub account.

  2. In your Jenkins job's configuration, go to Source Code Management > Git.

  3. Verify that Repository URL is the GitHub SSH URL (and not HTTPS).

  4. Next to Credentials, click Add. (Note you can also modify these keys as admin from Manage Jenkins > Manage Credentials.)

  5. In the Add Credentials dialog, fill in the fields as follows:

    • Kind - SSH username with private key
    • Username - <GitHub username>
    • Private key - Enter directly
    • Passphrase - <SSH key's passhrase if needed (or blank)>
    • Description - <Any description for this key>
  6. Copy and paste the contents of the GitHub user's private key file into the textbox for Private key. This should begin with --BEGIN RSA PRIVATE KEY-- and end with --END RSA PRIVATE KEY--.

    It should look like this: enter image description here

  7. Click Add. This adds the credential to the Credentials dropdown.

  8. In the Credentials dropdown, select the newly added key, identified by the previously entered username and description. Upon selecting the key, Jenkins should show you an error message inline if the key were invalid (in which case I recommend verifying the public key was entered correctly in GitHub and the private key in Jenkins).

  9. Save the job configuration.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!