Disable the password login, empty passwords and root login in /etc/ssh/sshd_config on Jenkins server and Docker node.
1
2
3
4
5
6
7
8
# Deny access for root via sshsed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
# Deny password authentication via sshsed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
# Deny using empty passwordssed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
# Enable public key authenticationsed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
Restart ssh daemon
1
systemctl restart sshd.service
Check can you login using private RSA key after disabling password login.
1
ssh -i id_rsa_docker_node jenkins@10.10.0.121
Add a Linux node to a master Linux server with Jenkins
Login to Jenkins web panel: http://10.10.0.113:8080
Then click Manage Jenkins β Manage nodes and clouds
Click + New Node on the left side panel.
Provide a node name
Select permanent agent
Set the description the same as node name
Set number of executors to 1 (it can be increased later)
Set remote root directory to /var/lib/jenkins
Set the label docker
Usage: use this node as much as possible
Launch method: Launch agents via SSH
Host: provide the IP address of the Docker node
Credentials β add β select Jenkins
Kind - choose from the dropdown list SSH username with private key
Provide a username: jenkins
Select enter directly
Paste the private key copied from the id_rsa_docker_node on a master Linux server with Jenkins (see the part: Generate RSA key for Docker node on a Jenkins server)
In the Description field provide a friendly name like RSA key for jenkins DOcker node or anything like that that will easily identify the credentials.
Provide a passphrase to this RSA private key you generated previously on a master Linux server.
Click add
Select newly created credentials from a dropdown list
Host Key Verification Strategy: choose: Known hosts file Verification Strategy
Availability: Keep this agent online as much as possible
In node properties select/check Environment variables and Tools Locations