“主机密钥验证失败"尽管存在 ssh_key,但在 Gitlab_ci 上 [英] "Host key verification failed" on Gitlab_ci although ssh_key is present
问题描述
主机密钥验证失败."在 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屋!