Fix “Host key verification failed” Error When Launching Jenkins Slave via SSH

We’re using Jenkins v1.549 with a newly added Linux node.

When trying to launch slave via execution of the command below on the master:

# ssh -24i /var/lib/jenkins/.ssh/key.pem [email protected] java -jar ~/slave.jar

The following error occurs:

“Host key verification failed”

The simple workaround is to connect to the Jenkins server via SSH, and run the following command accepting the connection:

# su - jenkins -c "ssh -24i /var/lib/jenkins/.ssh/key.pem [email protected]"
The authenticity of host '[example.com]:22' can't be established.
ECDSA key fingerprint is aa:bb:cc:00:11:22:33:44:55:66:77:88:99:aa:bb:cc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[example.com]:22' (ECDSA) to the list of known hosts.

This will add the host key for node.example.com to the /var/lib/jenkins/.ssh/known_hosts and the subsequent call of the master command above won’t generate the error.