Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in DevOps and Agile by (29.3k points)

I am successfully able to connect to a remote machine using SSH but when I am launching the agent from Jenkins it throws the following error:

ERROR: Server rejected the 1 private key(s) for user1 (credentialId:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/method:publickey)

[01/19/17 05:35:15] [SSH] Authentication failed.

hudson.AbortException: Authentication failed.

at hudson.plugins.sshslaves.SSHLauncher.openConnection(SSHLauncher.java:1219)

    at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:714)

    at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:709)

    at java.util.concurrent.FutureTask.run(FutureTask.java:266)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

    at java.lang.Thread.run(Thread.java:745)

[01/19/17 05:35:15] Launch failed - cleaning up connection

[01/19/17 05:35:15] [SSH] Connection closed.

I can establish SSH connection from a master machine to the node machine using user1, however, when I am trying to launch the agent using user1 from Jenkins it is rejecting the private key. Is there any solution to overcome this issue?

closed

4 Answers

+3 votes
by (50.2k points)
edited by
 
Best answer

The solution to overcome this problem is 

Goto slave node switch to the root user

sudo su

Add a user to jenkins home using

useradd -d /var/lib/jenkins jenkins

Here /var/lib/jenkins is having my home directory

Now, from jenkins master copy the id inside id_rsa.pub from jenkins user

cat /var/lib/jenkins/.ssh/id_rsa.pub

Now, create an authorized_keys file for jenkins user form slave node

mkdir /var/lib/jenkins/.ssh

And create an authorized_keys file

vi /var/lib/jenkins/.ssh/authorized_keys

Paste the id that you have copied from id_rsa.pub here and save the file with “:wq!”.

This will help you to resolve the issue.

For more information please go through the following tutorial to get more info about jenkins:

Why Jenkins says “Server rejected the 1 private key(s)” while launching the agent?
Intellipaat-community
by (29.3k points)
Thanks, It worked for me.
by (19.7k points)
Very well explained!
by (29.5k points)
this works! thanks!
by (33.1k points)
Thanks for this clearly explained answer!
by (32.1k points)
Perfect solution! Worked for me!
Thanks!
+2 votes
by (107k points)

I solved this issue by following the below steps:

1) Make sure you are on the correct path in both slave and master machines. You also need to sign in to the machines with the right user. Suppose 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 a .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 perform the above steps - 1 & 2 in your master machines as well.

4) You need to have ssh keys in both master and slave machines on the same path and with the 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 provide the same remote root directory - "/home/Jenkins" in your node configuration and select "manually trusted key verification strategy".

Why Jenkins says “Server rejected the 1 private key(s)” while launching the agent?
Intellipaat-community
by (19.9k points)
Very well explained. Thank you.
by (47.2k points)
It worked for me, Thank you
0 votes
by (44.4k points)

You can work around this issue by doing this at the end of the Dockerfile for the Jenkins slave.

RUN rm -f /run/nologin

0 votes
by (106k points)

I look like permissions are open change permissions to 600. rw------- by using below-mentioned way:-

permissions of 744 == rwxr-xr-x == read permissions for world and group 

permissions of 600 == rw------- == read/write permissions for owner user only

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...