Gitlab - 无法为 CI 和 CD 构建验证远程服务器

Gitlab - failed to authenticate remote server for CI and CD build

当我的“.gitlab-ci.yml 时出现“Enter passphrase for /dev/fd/63”错误" 尝试远程连接到我的 Ubuntu 服务器以执行 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

由于 openssh 是 Git 用于 Windows 的软件包,请尝试使用 openssh 密钥(使用 ssh-keygen 生成),没有(现在) 密码(以避免需要 ssh-agent)

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

我使用以下代码片段通过 .gitlab-ci.yml 作业进行 ssh,STAGING_SSH_KEY 作为变量存储在设置 -> CI/CD -> 变量

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"
     "