- Nikhil Bhaskar
- September 11, 2021
How to Configure SSH with Jenkins
Jenkins is a Free & open-source devops tools & used for CI/CD automation application. It is written in Java language. Jenkins provides SSH plugins such as ssh, ssh agent & publish over ssh. Using ssh plugins we can configure ssh with jenkins. We needs a private key to configure ssh with jenkins.
Install SSH plugins on Jenkins.
- First we needs to install ssh plugins on jenkins so click on link https://www.hackerxone.com/blog/how-install-ssh-plugins-jenkins
Create a user for access the jenkins jobs.
adduser user-name
or
adduser jenkins
Here is the command output.
Adding user `jenkins' ...
Adding new group `jenkins' (1002) ...
Adding new user `jenkins' (1002) with group `jenkins' ...
Creating home directory `/home/jenkins' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for jenkins
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
Add new user-name in sudoers file.
user-name ALL=(ALL:ALL) ALL
or
jenkins ALL=(ALL:ALL) ALL
Login to new user-name.
sudo su - user-name
Here is the command output.
user-name@
or
jenkins@
Create a .ssh forlder.
mkdir ~/.ssh
Create a authorized_keys.
vim ~/.ssh/authorized_keys
Paste a private/public key.
How to get public key/Private key.
- Run ssh-keygen command on Root user to create a key.
ssh-keygen
Here is the command output.
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:rsAb4BudQmMvizzaXBfjJ59sI0Hsdrlczv4PcV3ghDE root@HMECL003816
The key's randomart image is:
+---[RSA 3072]----+
| Eoo |
| .+ . |
| . . .|
| o ..|
| = oo S. . . .|
| + * o++o . o |
| = O.++o= . |
|.= B =.*=.o . |
|+.* . .o+o..... |
+----[SHA256]-----+
Open the public key file.
cat .ssh/id_rsa.pub ##public key
or
cat .ssh/id_rsa ##private key
Configure SSH with jenkins.
- Login to Jenkins Server.
- Provide user-name & password.
- Click on Manage configure.
- Click on Manage Credentials.
- Click on Jenkins.
- Click on Global Credentials(unrestricted) option.
- Click on adding some credentials.
- Select SSH username with private key.
- Provide Unique ID for key.
- Provide username.
- At private Key.
- Click on Add or paste the private key from .ssh/id_rsa
- Click on OK.
- SSH credentials is added successfully.