Jenkins, Host key verification failed, script returned exit code 255
It seems that the solution was to add the parameter StrictHostKeyChecking to the shell script line
sh "ssh -o StrictHostKeyChecking=no [email protected] 'echo $HOME'"
agusgambina
A Computer Engineer with over 7 years industry experience. I have worked on different types of companies like startups, and consulting companies, as a developer. I have built on my knowledge at work, studying at university and with personal research.
Updated on August 31, 2022Comments
-
agusgambina almost 2 years
I have a
building-server
where I have Jenkins 2.73.3 and another servers where I deploy my apps.I have also set up a credential to connect from
building-server
to the other servers.But everytime I add another server it is difficult to add it because I set up the authorized key in the new server and in the command line works, but not in Jenkins.
Here is a little recipe that fails:
pipeline { agent any stages { stage('Set conditions') { steps { sshagent(['xxxx-xxxx-xxxx-xxxx-xxxx']) { sh "ssh [email protected] 'echo $HOME'" } } } } }
And here is the Log failure:
[ssh-agent] Started. [Pipeline] { [Pipeline] sh [check] Running shell script + ssh [email protected] echo /var/lib/jenkins $ ssh-agent -k unset SSH_AUTH_SOCK; unset SSH_AGENT_PID; echo Agent pid 12567 killed; [ssh-agent] Stopped. Host key verification failed. [Pipeline] } [Pipeline] // sshagent [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 255 Finished: FAILURE
-
Damon about 6 yearsWhile this will work, this bypasses the verification that the target host is who you want to connect to and is a potential for exploit. You should instead add the target to the build agent's
~/.ssh/known_hosts
file by trying to ssh from each build agent to the target host (or from Jenkins master if not using build agents). See this answer to this question