Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins,主机密钥验证失败,脚本返回退出代码255_Jenkins_Ssh_Jenkins Pipeline - Fatal编程技术网

Jenkins,主机密钥验证失败,脚本返回退出代码255

Jenkins,主机密钥验证失败,脚本返回退出代码255,jenkins,ssh,jenkins-pipeline,Jenkins,Ssh,Jenkins Pipeline,我有一个构建服务器,在那里我有Jenkins 2.73.3和另一个服务器,我在那里部署我的应用程序 我还设置了一个凭据以从building server连接到其他服务器 但每次我添加另一台服务器时,都很难添加它,因为我在新服务器和命令行中设置了授权密钥,但在Jenkins中没有设置 以下是一个失败的小秘诀: pipeline { agent any stages { stage('Set conditions') { steps { sshagen

我有一个
构建服务器
,在那里我有Jenkins 2.73.3和另一个服务器,我在那里部署我的应用程序

我还设置了一个凭据以从
building server
连接到其他服务器

但每次我添加另一台服务器时,都很难添加它,因为我在新服务器和命令行中设置了授权密钥,但在Jenkins中没有设置

以下是一个失败的小秘诀:

pipeline {
  agent any

  stages {

    stage('Set conditions') {
      steps {
        sshagent(['xxxx-xxxx-xxxx-xxxx-xxxx']) {
          sh "ssh user@product.company.com 'echo $HOME'"
        }
      }
    }

  }
}
下面是日志失败:

[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
[check] Running shell script
+ ssh user@product.company.com echo /var/lib/jenkins
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 12567 killed;
[ssh-agent] Stopped.
Host key verification failed.
[Pipeline] }
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE

似乎解决方案是将参数StrictHostKeyChecking添加到shell脚本行

sh "ssh -o StrictHostKeyChecking=no user@product.company.com 'echo $HOME'"

虽然这会起作用,但这会绕过验证,即目标主机是您要连接的主机,并且可能会被利用。相反,您应该通过尝试从每个生成代理到目标主机(或者从Jenkins master,如果不使用生成代理),将目标添加到生成代理的
~/.ssh/known_hosts
文件中。注意可能的重复