Why Jenkins says "Server rejected the 1 private key(s)" while launching the agent? Why Jenkins says "Server rejected the 1 private key(s)" while launching the agent? jenkins jenkins

Why Jenkins says "Server rejected the 1 private key(s)" while launching the agent?


I solve this issue following below steps:

From the target slave node's console

  1. Switch to the root user:
sudo su
  1. Add a jenkins user with the home /var/lib/jenkins (Note: I am keeping my home directory in /var/lib/jenkins):
useradd -d /var/lib/jenkins jenkins

From the Jenkins Master

Copy the /var/lib/jenkins/.ssh/id_rsa.pub key from the Jenkins user on the master

From the target slave node's console

  1. Create an authorized_keys file for the Jenkins user
mkdir /var/lib/jenkins/.sshtouch /var/lib/jenkins/.ssh/authorized_keys
  1. Paste the key from the Jenkins master into the file vim. Save with :wq!

  2. Make sure the files have correct owner and permission.

chown -R jenkins /var/lib/jenkins/.sshchmod 600 /var/lib/jenkins/.ssh/authorized_keyschmod 700 /var/lib/jenkins/.ssh


I solved this issue by following the below steps:

1) Make sure you are on correct path in both slave and master machines. You also need to sign in to the machines with the right user. Say I need to create a new global jenkins user "jenkins" and I want my keys to be in the path "/home/jenkins/.ssh/", add "jenkins" user to the machines first.

2) Now create .ssh folder and generate ssh keys using the steps given in https://support.cloudbees.com/hc/en-us/articles/222978868-How-to-Connect-to-Remote-SSH-Slaves-

3) Make sure you do the above steps - 1 & 2 in your master machines as well

4) You need to have ssh keys in both master and slave machines in the same path and with same "jenkins" user permissions.

5) Finally, ssh both machine IPs to and fro to check the bidirectional connectivity from your terminal.

6) Configure jenkins credentials and nodes. Make sure you give the same remote root directory - "/home/jenkins" in your node configuration and select "manually trusted key verification strategy" - as suggested in https://linuxacademy.com/community/posts/show/topic/16008-jenkins-adding-a-slave


My Solution was:

$ user add -d /var/lib/jenkins jenkins$ sudo su$ passwd jenkins$ chown -R jenkins /var/lib/jenkins/.ssh/*$ chmod 700 .ssh

It worked after tampering around for 2 hours...