Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: Can't connect to Jenkins Slave No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts

Tags:

jenkins

Here are my jenkins config:enter image description here

enter image description here

Error message:

/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.

No matter how much I tried it doesn't work. I've read this post, but still no solution.

like image 364
Nicolas S.Xu Avatar asked Jun 08 '17 17:06

Nicolas S.Xu


2 Answers

I got the same error while launching slave.It has to do with the SSH Slave Plugin. What worked for me was changing the Host key verification strategy in LAUNCH METHOD from "Known Hosts file verification strategy" to "Manually trusted key verification strategy".

CONFIGURE AGENT -> LAUNCH METHOD -> Manually trusted key verification strategy - > SAVE.

Hope this helps.

like image 183
Binod Mathews Avatar answered Oct 21 '22 23:10

Binod Mathews


The problem is that Jenkins causes confusion by reporting that the file is missing under /var/jenkins_home/, which is a hard-coded value. Instead, it should be telling you that the file is missing under your actual $JENKINS_HOME path. That way, you would immediately know where to look.

So the easiest way to fix this is to:

  1. Go to the actual $JENKINS_HOME directory on your Jenkins master, and create a .ssh directory and known_hosts file under it, for example:

    $ mkdir $JENKINS_HOME/.ssh
    $ touch $JENKINS_HOME/.ssh/known_hosts
    
  2. If you've ever SSH-ed from Jenkins master to your slave machine before, then you should already have a known_hosts file under your ~/.ssh directory. If you don't, then SSH from Jenkins master to Jenkins slave machine and it will get automatically created for you under ~/.ssh directory for that user.

  3. Now open that ~/.ssh/known_hosts file and simply copy>paste the line that contains your slave machine's IP address to the $JENKINS_HOME/.ssh/known_hosts file. Alternative way is to copy the entire ~/.ssh/known_hosts file to $JENKINS_HOME/.ssh directory if that is easier for you.

like image 5
Goran Vasic Avatar answered Oct 21 '22 22:10

Goran Vasic