Friday, February 8, 2019

Jenkins Master Slave Setup | Setup Jenkins Master Slave on Ubuntu | Setup build agent and Integrate with Jenkins Master

Jenkins has powerful feature of master slave architecture which enables distributed builds. This article we will learn how to establish slave nodes on Ubuntu machines and integrate with Jenkins Master.

This lab demo is available on YouTube:
 Let us learn more about Jenkins master and slave:

Jenkins Master
Your main Jenkins server is the Master. The Master’s job is to handle:
  • Scheduling build jobs.
  • Dispatching builds to the slaves for the actual execution.
  • Monitor the slaves (possibly taking them online and offline as required).
  • Recording and presenting the build results.
  • A Master instance of Jenkins can also execute build jobs directly.
Jenkins Slave
A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves:
  • It hears requests from the Jenkins Master instance.
  • Slaves can run on a variety of operating systems.
  • The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master.
  • You can configure a project to always run on a particular Slave machine, or a particular type of Slave machine, or simply let Jenkins pick the next available Slave.
Lets see how to configure both Jenkins master and slave nodes on Ubuntu EC2.

Jenkins Master uses SSH keys to communicate with slave. You need to create ssh keys in Jenkins master by executing below command.


Slave node configuration(you need new micro Ubuntu instance for this slave)
only port 22 needs to be open

Install Java

sudo apt-get update
sudo apt-get install default-jdk -y

Install Maven
sudo apt-get install maven -y

Create User as Jenkins
sudo useradd -m jenkins
sudo -u jenkins mkdir /home/jenkins/.ssh

Add SSH Keys from Master to Slave 

Execute the below command in Jenkins master Ec2.
sudo cat ~/.ssh/

Copy the output of the above command:

Now go to Slave node and execute the below command
sudo -u jenkins vi /home/jenkins/.ssh/authorized_keys

This will be empty file, now copy the public keys from master into above file.
Once you pasted the public keys in the above file in Slave, come out of the file by entering wq!

Now go into master node
ssh jenkins@slave_node_ip

this is to make sure master is able to connect slave node. once you are successfully logged into slave, type exit to come out of slave.

Now copy the SSH keys into /var/lib/jenkins/.ssh by executing below command in master(make sure you exited from slave by typing exit command:

sudo cp ~/.ssh/known_hosts  /var/lib/jenkins/.ssh

Because jenkins master will look keys from the above folder.

Register slave node in Jenkins:
Now to go Jenkins Master, manage jenkins, manage nodes.

Click on new node. give name and check permanent agent.
give name and no of executors as 1. enter /home/jenkins as remote directory.
select launch method as Launch slaves nodes via SSH.
enter Slave node ip address as Host.

click on credentials. Enter user name as jenkins. Make jenkins lowercase as it is shown.
 Kind as SSH username with private key. enter private key of master node directly by executing below command:

sudo cat ~/.ssh/id_rsa
(Make sure you copy the whole key including the below without missing anything)

click Save.
select Host key verification strategy as "manually trusted key verification strategy".

Click Save.
Click on launch agent..make sure it connects to agent node.

Now you can kick start building the jobs, you will see Jenkins master runs jobs in slave nodes.


  1. This is great article and helpful but a small correction required.
    Command : sudo cp ~/.ssh/known_hosts /var/lib/jenkins/.ssh
    Need to be updated to
    sudo cp ~/.ssh/known_hosts /var/lib/jenkins/.ssh/known_hosts

  2. very god tq u helpfull this videos and docments again tq u

  3. SSHLauncher{host='', port=22, credentialsId='jenkins', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.ManuallyTrustedKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
    [10/02/22 21:18:01] [SSH] Opening SSH connection to
    [10/02/22 21:18:01] [SSH] SSH host key matches key seen previously for this host. Connection will be allowed.
    ERROR: Server rejected the 1 private key(s) for jenkins (credentialId:jenkins/method:publickey)
    ERROR: Failed to authenticate as jenkins with credential=jenkins Publickey authentication failed.
    at com.trilead.ssh2.auth.AuthenticationManager.authenticatePublicKey(
    at com.trilead.ssh2.Connection.authenticateWithPublicKey(
    at com.cloudbees.jenkins.plugins.sshcredentials.impl.TrileadSSHPublicKeyAuthenticator.doAuthenticate(
    at com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator.authenticate(
    at com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator.authenticate(
    at hudson.plugins.sshslaves.SSHLauncher.openConnection(
    at hudson.plugins.sshslaves.SSHLauncher.lambda$launch$0(
    at java.base/
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.base/java.util.concurrent.ThreadPoolExecutor$
    at java.base/
    Caused by: Could not generate signature
    at com.trilead.ssh2.signature.KeyAlgorithm.generateSignature(
    at com.trilead.ssh2.auth.AuthenticationManager.authenticatePublicKey(
    ... 10 more
    Caused by: Could not sign data
    at java.base/
    at java.base/$Delegate.engineSign(
    at java.base/
    at com.trilead.ssh2.signature.KeyAlgorithm.generateSignature(
    ... 11 more
    Caused by: javax.crypto.BadPaddingException: RSA private key operation failed
    at java.base/
    at java.base/
    at java.base/
    ... 14 more
    [10/02/22 21:18:01] [SSH] Authentication failed.
    Authentication failed.
    [10/02/22 21:18:01] Launch failed - cleaning up connection
    [10/02/22 21:18:01] [SSH] Connection closed.

    How do I fix this issue please???


Top 10 DevOps Popular Tools | Popular DevOps Tools You Must Know In 2024 | Learn DevOps Tools in 2024

Here are the top 10 DevOps Tools to focus on to put your DevOps learning on a  faster track  and kick start your career quickly as a success...