Gitlab-ci高山映像:主机密钥验证失败 [英] Gitlab-ci alpine image : Host key verification failed
本文介绍了Gitlab-ci高山映像:主机密钥验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在gitlab中,我使用 maven映像构建我的工作,然后将jar复制到ssh服务器->正常。
In gitlab I build my job with a maven image, then copy the jar to the ssh server -> it works fine.
对于php项目,我尝试使用高山图片。但是我被拒绝,因为 主机密钥验证失败。
For a php project, I try to use alpine image. But I get rejected with 'Host key verification failed'.
服务器和密钥相同。
不工作:
image: alpine:latest
stages:
- deploy
deploy:
before_script:
- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$SSH_PRIVATE_KEY")'
stage: deploy
script:
- ssh root@devsb01 "ls"
工作中:
image: maven:3.6.0-jdk-10-slim
stages:
- deploy
deploy:
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- '[[ -f /.dockerenv ]] && mkdir -p ~/.ssh && echo "$KNOWN_HOST" > ~/.ssh/known_hosts'
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
stage: deploy
script:
- ssh root@devsb01 "ls"
我认为这与ssh密钥的添加方式有关。
I think this has to do with the way the ssh key is add.
推荐答案
尝试将这些内容添加到两行:
try adding theses two lines:
- mkdir ~/.ssh
- ssh-keyscan -t rsa devsb01 >> ~/.ssh/known_hosts
对我有用!
您的文件将如下所示:
image: alpine:latest
stages:
- deploy
deploy:
before_script:
- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$SSH_PRIVATE_KEY")'
- mkdir ~/.ssh
- ssh-keyscan -t rsa devsb01 >> ~/.ssh/known_hosts
stage: deploy
script:
- ssh root@devsb01 "ls"
这篇关于Gitlab-ci高山映像:主机密钥验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文