I’m setting up an automation test on Jenkins. I’m trying to run a script remotely from one Linux machine(master machine, same machine as my Jenkins server) and calling a bunch of other scripts on another Linux machine(slave machine). However I’m getting this error on my first ssh command
Host key verification failed.
I’m pretty sure there is no problem for the passwordless connection from master to slave because I’ve run other tests previously using the same master/slave machine.
I run the exact same command manually on my master and it successfully returned the expected result. I don’t know why it just doesn’t work for the automation test.
All I wanted to do in this command is to check if a package is already installed (my OS is CentOS 7 for both machines)
ssh ${USERNAME}@${IP_ADDR} 'rpm -qa | grep ${MY_PACKAGE}'
I’m just checking the existence of the package before I proceed to more commands specific to this package.
2
Answers
Eventually I figured what was wrong with it.
When I was exchanging ssh host key from the two machines, I didn't use root user. However, when the test was running through Jenkins, it was using "sudo" to run the target script on the slave test machine, which means it was reading a ssh host key from the "known_hosts" file for root user, not the one I configured for the test user account (a non-root user account)! I merged my two "known_hosts" files for both the test user and the root user, then the problem was fixed because now Jenkins master could access my slave test machine through root user or my test user account.
Try this in your shell script. It disables the host key verification check for the hosts.