Setup SSH between Jenkins and Github
Please visit my website and subscribe to my youtube channel for more articles
In this blog, we will explore how to Setup SSH between Jenkins and Github for achieving the passwordless connection . Using this approach, you do not need to provide your credentials to configure the git repo in your Jenkins job
Agenda:
- Setup a user
jenkins
on your Jenkins server - Generate the SSH keys
- Copy the the public key in Github
- Configure in Jenkins Credentials
- Configure a sample job in Jenkins using SSH connection
Prerequisite:
- Jenkins should be installed
- Github account
Setup jenkins
user on jenkins server
- Generate the ssh keys
- Ensure the ssh-agent is running
sudo -su jenkinsssh-keygen
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa


SSH key is generated successfully for the jenkins
user
Now copy the .pub file using below command
cat /var/lib/jenkins/.ssh/id_rsa.pub
Github Configuration
- Go to Github repository -> Setting ->Deploy Keys

Configure Jenkins Credentials
Add SSH Key inside Jenkins
- Login to jenkins
- Navigate to Credentials from left panel in Jenkins console and then click on global or Go to Manage jenkins -> Manage Credentials
- After this, select ‘Add Credentials’:
- This will open a new form for us.
- In the Kind dropdown, select ‘SSH username with private key’ and then give a name for it.
- Copy the private key from the jenkins server for
jenkins
user

Now you can clone any git repo in this jenkins instance. You do not need to provide the credentials while configuring the job in Jenkins
Configure Jenkins Job
- Create a freestyle job in Jenkins
- Configure SSH url of your git repo
Summary:
Congratulation, we have successfully setup SSH between Jenkins and Github for achieving the password less connection . Using this approach, you do not need to provide your credentials to configure the git repo in your Jenkins job.