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

半腔热情 提交于 2019-11-28 02:00:47

问题


I am getting "Enter passphrase for /dev/fd/63" error when my ".gitlab-ci.yml" tries to remote to my Ubuntu server for executing SSH commands.

I have created a new variable called "STAGING_PRIVATE_KEY" and the value is the private key that I personally use to SSH to the server, but providing the same key to ".gitlab-ci.yml" fails to authenticate.

Below is my yml file:

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

回答1:


I use the below snippet to ssh using .gitlab-ci.yml job, STAGING_SSH_KEY is stored as a variable under 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:


Since openssh is package with Git for Windows, try and use an opeenssh key (generated with ssh-keygen), without (for now) a passphrase (to avoid needing an ssh-agent)

Register your openssh public key (default id_rsa.pub) on the AWS side.
As in, for instance, "Importing Your Own Public Key to Amazon EC2".



来源:https://stackoverflow.com/questions/48434818/gitlab-failed-to-authenticate-remote-server-for-ci-and-cd-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!