You are on page 1of 5

How to setup a Jenkins slave with ssh private key

(Copy and Past, Enter Directly Version)


Jing, mqjing@gmail.com

Quick Guide (4 steps)


ETA: 10 mins
Slave Machine
# init: [Slave] Create Account for Autobuild
slave:~$ sudo adduser jing_autobuild

# Step 1: Create private key and public key


slave:~$ ssh-keygen -t rsa -C "The access key for the slave Jing"
(note: Enter passphrase)
Output:
private key: id_rsa # copy to master
public key: id_rsa.pub # copy to slave (.ssh/authorized_keys)

# Step 2: Setup Authorized key


slave:~$ cat id_rsa.pub > ~/.ssh/authorized_keys

Jenkins Master Machine


# Step 3: Setup the Credential key
[Manage Jenkins] -> [Manage Credential] -> [Add Credentials]:
Select: SSH Username with private key

Info
# you are on the slave
(a) copy the private key
slave:~$ cd .ssh;cat id_rsa

# you are on the Jenkins master


(b) paste to the jenkins master board
Private key:
Enter directly: <private key ascii>

# Step 4: Create Node


[Manage Jenkins] -> [Manage Node] -> [New Node]
Info
Remote FS root: /home/jing_autobuild
Host: <slave ip>
Credentials: <select credentials>

Detail
Step 1: Create private key and public key (detail)

You are on slave machine


slave:~$ ssh-keygen -t rsa -C "The access key for the slave Jing"
Output:
private key: id_rsa # for jenkins master to connect this slave
public key: id_rsa.pub # for this slave to verify the connection from jenkins master
Note: You should enter a strong passphrase for your key. If you do not use passphrase,
anyone can commit your codes when the keys were stolen.
example:
Step 2: Setup the public key as the authorized key for verifying the credential key from the
master

You are on slave machine


slave:~$ cat id_rsa.pub > ~/.ssh/authorized_keys
example:

Step 3: Setup the the credential key

You are on the Jenkins master


[Manage Jenkins] -> [Manage Credential] -> [Add Credentials]:
Select: SSH Username with private key

Setup the username and key


Username: the username for access the slave machine
Key: copy private key
Step 1: cat the private key from the slave machine
ex:
# you are on the slave
slave:~$ cd .ssh;cat id_rsa

Step 2: copy the content to the jenkins master board


ex:
# you are on the jenkins master

Setup the credential for the node


[Manage Jenkins] -> [Manage Node] -> select node -> [Configure]

See the connection status

You might also like