Setup Credentials in Jenkins with GitHub

In this article, we delve into the significance of managing credentials for GitHub authorization and application deployment. We introduce Jenkins and its Credentials Plugin as a convenient solution for securely storing passwords and keys. By following the steps provided, readers can effectively set up and utilize the plugin for smooth and secure credential management in their projects.

To manage credentials, such as GitHub authorization or application deployment, storing passwords and keys is essential. Jenkins offers a convenient solution with the Credentials Plugin.


Jenikis Ubuntu github

Action Order:

  1. Install the Credentials Plugin on Jenkins.
  2. Generate SSH keys on the server (PRIVATE and PUBLIC).
  3. Store the keys in the application.
  4. Test the connection to verify successful authentication.

Installing the plugin in Jenkins using the GUI method.

After installation, you must restart Jenkins: your_server:8080/restart
In the menu you will see the installed plugin Credentials.

Now we need to generate SSH keys. Go to the server, in my case Ubuntu.

- ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mobaxterm/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mobaxterm/.ssh/id_rsa.
Your public key has been saved in /home/mobaxterm/.ssh/
The key fingerprint is:
SHA256:zn6qZ+ShWjqsmU/cE BS0BFVP
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|. .              |
|.. .             |
|. .    o .       |
|o ....o S E      |
|.* .+= +o. .     |
|*oo+o *+o..      |
|=B+B.=..+ .      |
|*+B.*o.+oo       |

Keys generated, 2 pieces, with the extension .pub PUBLIC key and respectively without the extension key PRIVATE.

Setup Jenkins for private GitHub repository.
There is a point here, there are two kinds of repositories on GitHub: public and private, and we will set the keys for the private repository.

You need to copy the PUBLIC (that’s the one with the extension .pub) key from the file on the server and put it on GitHub.

- cat

Next: Settings -> SSH GPG keys -> New SSH key

Insert the copied PUBLIC key and fill inTitle – example: Jenkins

The GitHub part is done, now let’s write the PRIVATE key on the Jenkins server.
Next in plugin Credentials в Jenkins: Global -> Add Credentials

In this example, we are considering an SSH connection with a private key. We fill in the fields.

Kind: Credentials. SSH Username with private key: By using ssh username, keys or passphrase.
Scope: Global/System. Choose Global.
ID: set Id: github-ssh-key
Description: –
Username: name on GitHub
Private Key: In this field, use Add to add the previously generated PRIVATE key.


You can now add the saved Credentials to projects. Via Credentials -> Add

After following the necessary steps to configure the Credentials Plugin and establish the connection between Jenkins and GitHub, you will notice that the red text indicating an unsuccessful connection is now gone. This signifies that Jenkins has successfully connected to the project on GitHub, using the configured credentials.

By properly managing and utilizing credentials, you can ensure secure authentication and streamline the deployment process in Jenkins.

Related Posts