ssh-keyscan do not d of gitlab job中的EC2实例公共钥匙

发布于 2025-02-07 09:52:37 字数 1104 浏览 5 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神仙妹妹 2025-02-14 09:52:37

已解决。我在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文