Node Connection Error


I’m new to Jenkins and I’m trying to connect a node through ssh. I’m getting the error below which after searching around seems to be common. I’m unsure on how to resolve it. This directory does not exist so it seems accurate. Do I need to create this directory?

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

Hello @seh640 and welcome to this community :wave:

Most of the time I add a jenkins user on the machine I want to use as a node, and then copy an SSH key so that I can easily connect to it through the controller later on.
I also create a link (bad, bad habit) from /home/jenkins to /var/lib/jenkins so /var/lib/jenkins/.ssh/known_hosts does exist. :thinking:
Your error makes me wonder if there’s a better (and official way) to configure a machine in order to make it a node.
Anyway… If you don’t want to change your process and use your existing folder, you could follow the steps below to create the know_hosts file:

  1. Log in to the remote node machine as a user who has sudo access.
  2. Create the directory /var/lib/jenkins/.ssh if it does not exist already: sudo mkdir -p /var/lib/jenkins/.ssh
  3. Set the correct permissions for the directory: sudo chown -R jenkins:jenkins /var/lib/jenkins/.ssh
  4. Create an empty known_hosts file: sudo touch /var/lib/jenkins/.ssh/known_hosts
  5. Set the correct permissions for the known_hosts file: sudo chmod 600 /var/lib/jenkins/.ssh/known_hosts
  6. Add the SSH host keys for your remote hosts to the known_hosts file. You can do this manually by using the ssh-keyscan command:
ssh-keyscan your-remote-hostname >> /var/lib/jenkins/.ssh/known_hosts

Replace your-remote-hostname with the hostname or IP address of your remote host.

After these steps, you should be able to connect to your node through SSH without the “No Known Hosts file was found” error.

Thanks Bruno. That helped. I didn’t create the link but I added directories and ran the commands and it worked. I think I also had a credential error when using the SSH and private key creds. Much appreciated. I’m sure I’ll have more issues.