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

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

问题描述

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

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

这是我的 gitlab_ci 的一部分,它应该登录到我的服务器并从 repo 运行脚本:

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

还有错误:

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

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

Why the error? The variables are set.

当我从本地计算机和 Gitlab 手动执行相同操作时,私钥确实有效.

推荐答案

除了Git报错:Host Key Verification Failed"时连接到远程存储库,检查您的 .known_hosts 文件.

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

如果相同的私钥在本地工作,那可能是因为在本地,您的 ~/.ssh/known_hosts 文件确实包含ssh_keyscan 您要连接的远程服务器.
确保你的 GitLab CI 工作也是如此.

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天全站免登陆