Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying from Jenkins server to another server: Host key verification failed

Tags:

scp

jenkins

I am trying to deploy to another server from Jenkins server, and I can't do it using Jenkins Build script.

When I am on the Jenkins server, I can deploy. For example:

:/var/lib/jenkins/workspace/MyProject$ scp my_file ubuntu@my_address:~/MyProject

Runs perfectly fine; however,

When I specify:

scp my_file ubuntu@my_address:~/MyProject

In "Execute Shell" under build in Jenkins window. I get the following error:

Host key verification failed.

I know that the first time I ran the above command directly on Jenkins server, I was prompted:

The authenticity of host 'my_address (my_address)' can't be established.
ECDSA key fingerprint is cf:4b:58:66:d6:d6:87:35:76:1c:aa:cf:9a:7c:78:cc.
Are you sure you want to continue connecting (yes/no)?

So I had to hit "yes" in order to continue. But since I already directly in the terminal, I don't have to do anything extra.

Second answer to this question: Jenkins Host key verification failed

indicates that, if I understand it correctly.

What am I missing? What can I do to fix my problem?

like image 316
Akavall Avatar asked Jul 23 '16 18:07

Akavall


2 Answers

I got it working, I needed to do two things:

1) I had to use -o StrictHostKeyChecking=no:

scp -v -o StrictHostKeyChecking=no my_file ubuntu@my_address:~/MyProject

instead of:

scp my_file ubuntu@my_address:~/MyProject

2) I needed to copy my id_rsa to /var/lib/jenkins/.ssh

The /var/lib/jenkins/.ssh folder and files inside of it need to be owned by jenkins.

like image 149
Akavall Avatar answered Oct 18 '22 05:10

Akavall


Old question but may be someone would find this useful:

ssh root@jenkinsMaster 'echo "$(ssh-keyscan -t rsa,dsa jenkinsSlave)" >> /root/.ssh/known_hosts'

like image 35
Marco M Avatar answered Oct 18 '22 03:10

Marco M