【问题标题】:Gitlab - failed to authenticate remote server for CI and CD buildGitlab - 无法对 CI 和 CD 构建的远程服务器进行身份验证
【发布时间】:2018-07-04 05:26:20
【问题描述】:

当我的“.gitlab-ci.yml”尝试远程连接到我的 Ubuntu 服务器时,我收到“Enter passphrase for /dev/fd/63”错误执行 SSH 命令。

我创建了一个名为“STAGING_PRIVATE_KEY”的新变量,其值是我个人用于 SSH 到服务器的私钥,但为 ".gitlab- 提供相同的密钥ci.yml" 验证失败。

下面是我的 yml 文件:

deploy_staging:
  stage: deploy
  before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - mkdir -p ~/.ssh
  - eval $(ssh-agent -s)
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
    - ssh-add <(echo "$STAGING_PRIVATE_KEY" | base64 --decode)
    - cd test
    - git pull
    - echo "deployed to staging server"
  environment:
    name: staging
    url: MY SERVER

【问题讨论】:

    标签: gitlab gitlab-ci gitlab-ci-runner


    【解决方案1】:

    我使用下面的sn-p使用.gitlab-ci.yml作业进行ssh,STAGING_SSH_KEY作为变量存储在Settings -> CI/CD -> Variables下

    variables:
        GIT_SSL_NO_VERIFY: "true"
    
    image: someimage:latest #replace with any valid image which has ssh installed
    
    before_script:
      - mkdir -p ~/.ssh
      - echo -e "$STAGING_SSH_KEY" > ~/.ssh/id_rsa
      - chmod 600 ~/.ssh/id_rsa
      - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    
    stages:
     - deploy
    
    deploy_STAGING_job:
      stage: deploy
      script:
       - echo "ssh into the below random IP"
       - ssh myuser@10.200.200.200"
         echo "Login using ssh to remote instance"
         "
    

    【讨论】:

      【解决方案2】:

      由于 openssh 是与 Git for Windows 一起打包的,因此请尝试使用 openessh 密钥(使用 ssh-keygen 生成),没有(目前)密码短语(以避免需要 ssh-agent)

      在 AWS 端注册您的 openssh 公钥(默认 id_rsa.pub)。
      例如,“Importing Your Own Public Key to Amazon EC2”。

      【讨论】:

        猜你喜欢
        • 2020-11-08
        • 2019-03-11
        • 1970-01-01
        • 1970-01-01
        • 2014-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多