git 尽管存在 ssh_key,但 Gitlab_ci 上的“主机密钥验证失败”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52544473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Host key verification failed" on Gitlab_ci although ssh_key is present
提问by Oddamati
"Host key verification failed." on Gitlab_ciwhen running "ssh name@server"
“主机密钥验证失败。” 在运行“ssh name@server”时在 Gitlab_ci上
Here's a part of my gitlab_ci which is supposed to login to my server and run scripts from the repo:
这是我的 gitlab_ci 的一部分,它应该登录到我的服务器并从 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.
当我从本地计算机和 Gitlab 手动执行相同操作时,私钥确实有效。
回答by VonC
In addition of Git error: “Host Key Verification Failed” when connecting to remote repository, check your .known_hosts file.
除了Git 错误:连接到远程存储库时“主机密钥验证失败”,请检查您的 .known_hosts 文件。
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/known_hosts 文件确实包含ssh_keyscan
您要连接的远程服务器的 。
确保您的 GitLab CI 工作也如此。