How to create Jenkins-agent using ssh
#90DaysOfDevOps
#Day27
What is sh-keygen ?
sh-keygen
is a tool for creating new authentication key pairs for SSH.
To connect the Jenkins-agent and Jenkins Controller through ssh follow the steps below.
In the Jenkins Controller CLI ,go inside the hidden .ssh folder inside Ubuntu home directory using
cd .ssh/
enter the command
ssh-keygen
to generate key-pairsHere id_rsa.pub is a public key, so we will give it to our jenkins-agent.
In agent CLI, enter
cd .ssh
>vi authorized_keys
, and paste the content of id_rsa.pub inside .Now go to Jenkins Controller
Click Dashboard > Manage Jenkins > Nodes > New Node
enter the name of your node, and then select Permanent Agent > Create
Description: will contain your agent description
Number of executors: It should be less than equal to no.of CPUs you are working with, in our case it will be 1.
Remote root directory: it's asking where you want to create the working directory of our agent.
Labels: are basically keywords through which we will recognize agents while assigning work
In the Launch method section select Launch agents via SSH
Inside the Host enter the agent's IP address
Below Credentials section click on Add > jenkins
Now Jenkins Credentials Provider: Jenkins tabs open
In the Kind section, Select SSH Username with private key
ID :agent1
Description :agent1 credential
Username: ubuntu
below Private key , Select Enter directly , and in key section , Click on ADD paste the content of id_rsa key here .(Since our agent already have the public key so here we are adding the private key to our jenkins )
Click on Add .
Now select the created Credentials
-
Click SAVE
-
Your agent1 is created