ssh-keyscan do not d of gitlab job中的EC2实例公共钥匙
我在GitLab CI/CD管道上工作,该管道应将Docker容器部署到AWS EC2实例。我正在尝试实施描述的方法在这里我的一项工作正在失败,因为ssh-keyscan< ip>
不起作用。 我的管道看起来像这样:
...
deploy-to-staging:
image: docker:20.10.14
stage: deploy to staging
needs: ["docker-stuff"]
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $EC2_IP >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
...
它在-ssh-keyscan $ ec2_ip>>中失败。 〜/.ssh/nown_host
与错误:作业失败:退出代码1
。
我的gitlab变量:
- ssh_private_key -.pem格式的ec2键配方
- ec2_ip -public ipv4 dns
我已经尝试过ssh -keyscan< ipv4 dns dns或ip>
本地,并且它起作用。我还在单独的Ubuntu EC2实例上尝试了它,并且没有输出。
任何帮助将不胜感激。
I work on GitLab ci/cd pipeline that should deploy docker containers to AWS ec2 instance. I'm trying to implement approach described here and one of my jobs is being failed because ssh-keyscan <ip>
doesn't work.
My pipeline looks like that:
...
deploy-to-staging:
image: docker:20.10.14
stage: deploy to staging
needs: ["docker-stuff"]
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $EC2_IP >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
...
It fails at - ssh-keyscan $EC2_IP >> ~/.ssh/known_hosts
line with ERROR: Job failed: exit code 1
.
My GitLab varables:
- SSH_PRIVATE_KEY - EC2 key-pair private key of .pem format
- EC2_IP - Public IPv4 DNS
I've tried ssh-keyscan <ipv4 DNS or IP>
locally and it works. I've also tried it on separate ubuntu ec2 instance and it has no output.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决。我在AWS安全组中有错误的出站规则。我将SSH IP更改为0.0.0.0/0,并且已经有效。希望这对某人有帮助。
Solved. I had wrong outbound rules in aws security group. I've changed SSH IP to 0.0.0.0/0 and it have worked. Hope this will help someone.