Explore Courses Blog Tutorials Interview Questions
+2 votes
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(

    at hudson.plugins.sshslaves.SSHLauncher$

    at hudson.plugins.sshslaves.SSHLauncher$


    at java.util.concurrent.ThreadPoolExecutor.runWorker(

    at java.util.concurrent.ThreadPoolExecutor$


[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?


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 from jenkins user

cat /var/lib/jenkins/.ssh/

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 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:

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!
+2 votes
by (108k 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

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".

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

Browse Categories