SCP command fails to copy "Host key verification failed." SCP command fails to copy "Host key verification failed." jenkins jenkins

SCP command fails to copy "Host key verification failed."


scp -v is you friend here. This is the verbose flag for scp.

I suspect that the user you are testing with on the box and the user that Jenkins runs as are two different users, so the initial key exchange has never happened for the Jenkins user and Jenkins is headless so it has no ability to type yes to accept the host identification key.

If this is the case you can use the -o "StrictHostKeyChecking=no" option with scp to auto-accept and allow you to pass here.

Add the -v flag to your scp command and I bet we can see the what is going on in the output.

Here is the man page for scp

https://linux.die.net/man/1/scp

Good Luck


I found the all mistakes done by me. in this case. as i am new to this i don't aware of many things.so i like to mention the steps which are all done by me to complete this step. if anything i am doing is incorrect or which can be done in different way please suggest. Thanks.

1st was as Darrell mentioned in answers i added the -o "StrictHostKeyChecking=no" in my SCP command which was like this

   scp -v -o StrictHostKeyChecking=no -i /home/ubuntu/connec/new_one.pem **/target/*.jar ubuntu@00.00.00.00:/home/ubuntu

still i faced the error as

    Load key "/home/ubuntu/connec/new_one.pem": Permission denied    debug1: No more authentication methods to try.

after searching about the error in google and stackoverflow i found that it's permission issue for the user of Jenkins. when i submit the command in terminal i was using the user as ubuntu but jenkin uses the user as "jenkins". so i have done 2 changes added sudo in my scp command

    sudo scp -v -o StrictHostKeyChecking=no -i /home/ubuntu/connec/new_one.pem target/*.jar ubuntu@00.00.00.00:/home/ubuntu

and then i faced that "Jenkins" user don't have authority to run sudo command so i have edited the file name "VISUDO"

 sudo visudo

and in last added the line

 jenkins ALL=(ALL) NOPASSWD: ALL

after that when i ran the pipeline it completed and copied the file...yaayyy.

Still i am wondering am i doing correctly?? any other way is there?