Linux – Jenkins – Host key verification failed

Jenkinslinuxssh

While I have no problems making an SSH connection from one server to another, my Jenkins is still having a trouble connecting to the remote server while executing a managed script, which is as follows.

$ssh root@xxx.xxx.xxx.xxx

And the following is the message that is produced by Jenkins while building the project.

$ /bin/sh /tmp/build_step_template8225836097820612990.sh
Host key verification failed.

Additional information will be uploaded upon request.

Best Answer

There are two ways to fix that.

First one is: Log into your Jenkins server and manually ssh to that machine and accept the key.

Second one is: Add the following to your ssh command:

-o StrictHostKeyChecking=no

Example:

ssh -i ~/.ssh/key.pem -o StrictHostKeyChecking=no ubuntu@1.1.1.1