Host key verification failed.

The account running jenkins likely has a bad value for the host key for the machine you are sshing to in ~/.ssh/known_hosts.


Well I replaced the know_host files but I was still having issues. so for anyone that has issues with the know_host file you would fix the offending key by doing a:

ssh-keygen -R hostnameOfOfendingKey

and this will remove the ofending key and now your known_host file is working again.

NOW to resolve the other issue I found the answer in this other place: https://stackoverflow.com/questions/25755418/executing-rsync-in-jenkins/25770519#25770519

and This was what I did to solve it

sudo su jenkins -s /bin/bash

then once as jenkins user copy my ssh key to the server I want to connect/execute commands in, etc

ssh-copy-id [email protected]

it then will present you this

[email protected]'s password: 
Now try logging into the machine, with "ssh '[email protected]'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

then I did this for testing purposes:

bash-4.1$ rsync -PSauve ssh --exclude=JenkinsBuild /srv/pd/* [email protected]:/srv/pdc/test1  

and it passed without asking for password or anything. Notice that I'm still log as jenkins.

So now when I created the Jenkins job with some shell commands as part of the build it will work as expected :D


I had a similar problem.

In my case jenkins was not executing rsync with the expected user (jenkins) but with another (jboss in my case) adding 'whoami' to the script and using ssh verbose:

rsync -e "ssh -v" .......

helped to find the problem.