Gitlab 为 digitalocean 服务器返回 Permission denied (publickey,password) [英] Gitlab returns Permission denied (publickey,password) for digitalocean server

查看:10
本文介绍了Gitlab 为 digitalocean 服务器返回 Permission denied (publickey,password)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 DigitalOcean 液滴上为我的 dockerized Django 应用程序实现 CD.

I'm trying to implement CD for my dockerized Django application on the DigitalOcean droplet.

这是我的.gitlab-ci.yml:

Here's my .gitlab-ci.yml:

image:
  name: docker/compose:1.29.1
  entrypoint: [""]

services:
  - docker:dind

stages:
  - build
  - deploy

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2

before_script:
  - export IMAGE=$CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
  - export WEB_IMAGE=$IMAGE/web:web
  - export NGINX_IMAGE=$IMAGE/nginx:nginx
  - apk add --no-cache openssh-client bash
  - chmod +x ./setup_env.sh
  - bash ./setup_env.sh
  - docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY

build:
  stage: build
  script:
    - docker pull $IMAGE/web:web || true
    - docker pull $IMAGE/web:nginx || true
    - docker-compose -f docker-compose.prod.yml build
    - docker push $IMAGE/web:web
    - docker push $IMAGE/nginx:nginx

deploy:
  stage: deploy
  script:
    - mkdir -p ~/.ssh
    - echo "$PRIVATE_KEY" | tr -d '
' > ~/.ssh/id_rsa
    - cat ~/.ssh/id_rsa
    - chmod 700 ~/.ssh/id_rsa
    - eval "$(ssh-agent -s)"
    - ssh-add ~/.ssh/id_rsa
    - ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
    - chmod +x ./deploy.sh
    - scp  -o StrictHostKeyChecking=no -r ./.env ./docker-compose.prod.yml root@$DO_PUBLIC_IP_ADDRESS:/Pythonist.org
    - bash ./deploy.sh
  only:
    - master

我已将我的 Publick 密钥复制到生产服务器(DO droplet).构建作业成功,但部署阶段失败并出现以下错误:

I have copied my Publick key to the production server (DO droplet). The build job is successful but the deploy stage failed with the following error:

$ chmod 700 ~/.ssh/id_rsa
$ eval "$(ssh-agent -s)"
Agent pid 26
$ ssh-add ~/.ssh/id_rsa
Identity added: /root/.ssh/id_rsa (abdul12391@gmail.com)
$ ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
$ chmod +x ./deploy.sh
$ scp  -o StrictHostKeyChecking=no -r ./.env ./docker-compose.prod.yml root@$DO_PUBLIC_IP_ADDRESS:/Pythonist.org
Warning: Permanently added '143.198.103.99' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
root@143.198.103.99: Permission denied (publickey,password).
lost connection
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

推荐答案

在数字海洋服务器上尝试如下:

Try the following on the digital ocean server:

cat ~/.ssh/id_rsa.pub

并将公钥复制到授权密钥

and copy the public key to authorized keys

nano ~/.ssh/authorized_keys

然后更改权限

chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/id_rsa

这篇关于Gitlab 为 digitalocean 服务器返回 Permission denied (publickey,password)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆