Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-73750

jenkins does not find known_hosts file in home directory

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • git-plugin
    • None

      running version 2.475-jdk17 docker image, I am unable to have jenkins find the known_hosts file.

      The $JENKINS_HOME directory is /var/jenkins_home.

      I've created the .ssh directory in $JENKINS_HOME, set permissions both 644 and 600 on separate occasions.

      The permissions of the known__hosts file are 644. The owner of both the .ssh directory and known hosts file are jenkins. Jenkins is running as user jenkins

      With the git host key verification set to known hosts, I am getting the following error:

      `You're using 'known hosts file' strategy to verify ssh host keys, but your known_hosts file does not exist, please go to 'Manage Jenkins' -> 'Security' -> Git Host Key...' and configure host key verification`.

       

      If I manually enter the hosts, everything is just fine and the warning go away. This makes me kinda sad

          [JENKINS-73750] jenkins does not find known_hosts file in home directory

          Mark Waite added a comment - - edited

          There must be a mistake in some part of your steps to either create or use that known_hosts file. I am able to use the known hosts method with the following Dockerfile:

          FROM jenkins/jenkins:2.475-jdk17
          
          RUN mkdir -m 700 -p ~/.ssh && ssh-keyscan bitbucket.org gitlab.com github.com > ~/.ssh/known_hosts
          

          I built the container image with the command:

          tag=$(( tag + 1 ))
          docker build -t jenkins-73750:$tag .
          

          I run the container image with the command:

          docker run --rm -i -t -p 8080:8080 jenkins-73750:$tag
          

          Once it is running, I complete the setup wizard by creating an account and installing the git plugin, the folders plugin, and the Pipeline plugins. Then I use "Manage" -> "Security" to configure host key recognition to use known hosts. I create an ssh private key credential and use it a a job definition that clones a private repository with ssh.

          The known_hosts file must exist on both the controller and the agent. It must be in the correct location on both the controller and the agent. It must have the correct permissions on both the controller and the agent.

          Mark Waite added a comment - - edited There must be a mistake in some part of your steps to either create or use that known_hosts file. I am able to use the known hosts method with the following Dockerfile: FROM jenkins/jenkins:2.475-jdk17 RUN mkdir -m 700 -p ~/.ssh && ssh-keyscan bitbucket.org gitlab.com github.com > ~/.ssh/known_hosts I built the container image with the command: tag=$(( tag + 1 )) docker build -t jenkins-73750:$tag . I run the container image with the command: docker run --rm -i -t -p 8080:8080 jenkins-73750:$tag Once it is running, I complete the setup wizard by creating an account and installing the git plugin, the folders plugin, and the Pipeline plugins. Then I use "Manage" -> "Security" to configure host key recognition to use known hosts. I create an ssh private key credential and use it a a job definition that clones a private repository with ssh. The known_hosts file must exist on both the controller and the agent. It must be in the correct location on both the controller and the agent. It must have the correct permissions on both the controller and the agent.

            Unassigned Unassigned
            drob0362 Robert
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: