Today, it happend again. I got the failure "Host key verification failed", while setting up a CI job where I wanted to use rsync. And as always with my lizard brain, I googled the error and found the solution to disable the host key checking.

But that is not the correct way to do this, the correct solution is as follows:

  1. Get the public key of the server you want to connect to, with ssh-keyscan.

  2. Add the public key to your CIs variables.

  3. Append the known_hosts file on the build container with the content of the created variable.

It’s even not that much more effort and you have an additional check against unexpected changes.