I trying to use by_ssh to run a script from the remote. I Created a user “xxx” in both server1 and server2.
Also configured the ssh , I am able to login to server2 from server1 as “xxx” user without password.
I created the below simple by_ssh server to run a basic script but it fails with “Remote command execution failed: Host key verification failed” Error.
To emphasise what @rivad has written, you should not create an user on server1 to login on server2. Depending on you distribution icinga runs as icinga or nagios. For this user you need to configure ssh connection to the user on server2. To do so you could run e.g.
sudo -u nagios bash
ssh testprod@server2
Once this is working with without asking for a password, your checks will work as well.
Since this thread was just revived, I wanted to warn that this configuration is potentially dangerous!
According to the section in ssh_config(5), “[i]f this flag is set to no or off, ssh will automatically add new host keys to the user known hosts files and allow connections to hosts with changed hostkeys to proceed, subject to some restrictions.” In other words, this allows MITM attacks.
Please try to verify the peer’s public key once, which can also be done via some script.
In case you are unable to do so and want to proceed with StrictHostKeyChecking, then set it to accept-new.