Host key verification failed - ssh command issue

Hi everyone,
It is my first time using Jenkins to create a job that executes a shell script, the script is to ssh to hardware and run some tests inside. Unfortunately the jenkins build failed with this error Host key verification failed.
below is the debug info

OpenSSH_8.4p1 Debian-5, OpenSSL 1.1.1k  25 Mar 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.xxx.xxx [192.168.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/jenkins/.ssh/id_rsa type -1
debug1: identity file /home/jenkins/.ssh/id_rsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_dsa type -1
debug1: identity file /home/jenkins/.ssh/id_dsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519 type 3
debug1: identity file /home/jenkins/.ssh/id_ed25519-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519_sk type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/jenkins/.ssh/id_xmss type -1
debug1: identity file /home/jenkins/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.4p1 Debian-5
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.0
debug1: match: OpenSSH_8.0 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.xxx.xxx:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:g6ZCEtl886IZn8mL87PSNpNPsksdCOVHfki0fcZFmYo
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.
Build step 'Execute shell' marked build as failure
Finished: FAILURE

How to solve this issue?
Thanks.

Does it work if you run the same command from the command line as the same user that Jenkins is running as? You need to get the host key of the system and make sure it is in the known_hosts file for the Jenkins user.

1 Like