“主机密钥验证失败";尽管存在ssh_key,但在Gitlab_ci上 [英] "Host key verification failed" on Gitlab_ci although ssh_key is present

查看:93
本文介绍了“主机密钥验证失败";尽管存在ssh_key,但在Gitlab_ci上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主机密钥验证失败." 在Gitlab_ci上运行时在Gitlab_ci上

这是我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手动执行相同操作时,私钥起作用.

解决方案

除了 Git错误:当主机密钥验证失败"时连接到远程存储库,请检查您的.known_hosts文件.

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

"Host key verification failed." on Gitlab_ci when running "ssh name@server"

Here's a part of my gitlab_ci which is supposed to login to my server and run scripts from the repo:

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

And the errror:

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

Why the error? The variables are set.

The private key does work when I'm doing the same thing manually from my local computer and Gitlab.

解决方案

In addition of Git error: "Host Key Verification Failed" when connecting to remote repository, check your .known_hosts file.

If that same private key is working locally, that might be because, locally, your ~/.ssh/known_hosts file does include the ssh_keyscan of the remote server you want to connect to.
Make sure your GitLab CI job does too.

这篇关于“主机密钥验证失败";尽管存在ssh_key,但在Gitlab_ci上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆