Gitlab - 无法对 CI 和 CD 构建的远程服务器进行身份验证 [英] Gitlab - failed to authenticate remote server for CI and CD build
问题描述
当我的.gitlab-ci.yml"尝试远程连接到我的 Ubuntu 服务器时,我收到Enter passphrase for/dev/fd/63"错误执行 SSH 命令.
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.
我创建了一个名为STAGING_PRIVATE_KEY"的新变量,其值是我个人用于 SSH 到服务器的私钥,但为 ".gitlab- 提供相同的密钥ci.yml" 验证失败.
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.
下面是我的 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 *
StrictHostKeyChecking no
" > ~/.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-ci.yml
作业进行 ssh,STAGING_SSH_KEY 作为变量存储在 Settings ->CI/CD -> 变量
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 *
StrictHostKeyChecking no
" > ~/.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"
"
这篇关于Gitlab - 无法对 CI 和 CD 构建的远程服务器进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!