尽管存在ssh_key,但Gitlab_ci上的“主机密钥验证失败”

时间:2018-09-27 20:13:28

标签: git gitlab gitlab-ci ssh-keys gitlab-ci-runner

“主机密钥验证失败。” 在Gitlab_ci上运行“ ssh name @ server”

这是我gitlab_ci的一部分,应该登录我的服务器并从存储库中运行脚本:

script:
  - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
  - eval $(ssh-agent -s)
  - ssh-add <(echo -e "$SSH_PRIVATE_KEY")


  - echo "debug"
  - echo "$SSH_PRIVATE_KEY" # all is ok here, it'll be printed
  - echo "debug"


  # - here comes an error
  - (cat ./script/script1.sh) | ssh -t -t $SSH_USERNAME@$SSH_HOST

错误:

  Host key verification failed.
  ERROR: Job failed: exit code 1

为什么会出错?变量已设置。

当我从本地计算机和Gitlab手动执行相同操作时,私钥起作用。

1 个答案:

答案 0 :(得分:2)

除了Git error: “Host Key Verification Failed” when connecting to remote repository,还检查您的.known_hosts文件。

如果相同的私钥在本地工作,那可能是因为您的〜/ .ssh / known_hosts文件在本地执行您要连接的远程服务器的include the ssh_keyscan
确保您的GitLab CI作业也是如此。