“Host key verification failed” on Gitlab_ci although ssh_key is present

家住魔仙堡 提交于 2019-12-09 13:40:10

问题


"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.


回答1:


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.



来源:https://stackoverflow.com/questions/52544473/host-key-verification-failed-on-gitlab-ci-although-ssh-key-is-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!