# Jenkins Master-Slave Configuration

In Jenkins, a **master-slave configuration** (also referred to as **controller-agent** configuration) involves setting up a primary Jenkins instance (the **master** or **controller**) that manages jobs, configurations, and orchestrates the build processes, and one or more additional machines (the **slaves** or **agents**) that execute the actual build tasks.

> Agenda:

1. Create 2 EC2 instances for the master machine & slave machine
    
2. Install Java & Jenkins in the Master machine
    
3. Generate SSH key pairs in the Master machine
    
4. Install Java in the slave machine
    
5. Configure the authorised key in the slave machine.
    
6. Setup of nodes in Jenkins server UI (Master Machine)
    

**<mark>Step 1 : Create 2 EC2 instances for the master machine &amp; slave machine</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722731997792/e34fa276-fc61-4728-8978-c48fc4d1cd3f.png align="center")

**<mark>Step 2 : Install Java &amp; Jenkins in the Master machine</mark>**

I have already installed both.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722732265098/bc24dece-abda-4592-baf2-896e916140b7.png align="center")

Jenkins service is running

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722681063022/617ad4f7-8f06-4de7-91e9-93c02714e153.png align="center")

**<mark>Step 3 : Generate SSH key pairs in the Master machine</mark>**

Generate SSH key pairs on Master machine

```plaintext
ssh-keygen -t rsa
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722732398457/bc5a453c-0c46-4dfd-b266-fb32c8081fbf.png align="center")

Go to SSH path & Check Keypair

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722732640727/93182331-ec17-45f4-a0dc-4d10036c9ca7.png align="center")

**<mark>Step 4 : Install Java in the slave machine</mark>**

I have already installed.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722733741942/61175c1b-f51b-4508-84de-6aeb1126a5fb.png align="center")

**<mark>Step 5 : Configure the authorised key in the slave machine.</mark>**

Go to Master machine, Copy the public key "**id\_rsa.pub**"

```plaintext
cat id_rsa.pub
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722732763777/27678f93-54d9-492d-8b2e-01638ac20a2d.png align="center")

Go to slave machine :

Paste the authorized key in the slave machine

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722733379157/b7dfc0f8-728c-46a3-a00c-6d5c97e0a318.png align="center")

**<mark>Step 6 : Setup of nodes in Jenkins server UI (Master Machine)</mark>**

Go to manage Jenkins & Click on Nodes

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722733830962/582ceb74-c4c0-41ae-9c74-94f98df8d257.png align="center")

Click on "New Node"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722733871368/b752ac8b-593d-4098-9161-be18e5b47bad.png align="center")

Enter node name, Click Permanent Agent & Click create

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722733941634/690d1b14-ec74-4bde-b2f7-1099edab43b4.png align="center")

Go to Slave Machine & Copy the /home/ubuntu directory or Create new directory

Set number of executer, your need

In "Remote directory", paste the /home/ubuntu

Set labels "Any"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722735799450/e87c23ba-fad4-4b64-9fbe-14ae3416705d.png align="center")

Click on "Launch method" - Choose "Launch agents via ssh"

In Host, Enter the Slave machine public ip address

Click on credentials - Add

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722734554330/00c0263f-ad27-4307-a445-1fc53e1a56d4.png align="center")

In Kind, Select "SSH Username with private key"

In ID, Set any name

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722734796059/9f7de423-7cc8-4121-9573-f0f3e8dc0236.png align="center")

In username, Enter Slave machine User name

In Private key, Copy the private key from master machine & Paste it

Scroll down, Click "Add"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722735025370/6b5c756c-91dd-4a79-9eb8-4fc90736df6a.png align="center")

Choose create credentials

In host key verification strategy, Select "Non............." & Click "Save"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722735121571/ab652733-5665-4cd1-8899-e074f009b5f9.png align="center")

Now, Slave machine configured successfully in the Jenkins master machine node

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1722735309288/d056d698-bae9-4090-a356-67199ca28045.png align="center")
