user @ ip:权限被拒绝(公钥)。?

时间:2019-08-12 13:58:03

标签: git ssh

尝试将自己的自托管git-lab服务器推送到另一台服务器, 而我正试图推动掷CI / CD和git-lab跑步者

我的.gitlab-ci是:

stages:
  - build
  - test

before_script:
  - 'which ssh-agent || ( apt-get install -qq openssh-client )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - mkdir -p ~/.ssh
  - chown $USER ~/.ssh/config
  - chmod 600 ~/.ssh/config
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

build:
  stage: build
  script:
    - echo "Building..."
    - ssh $DEPLOY_USER@$DEPLOY_SERVER "cd var/www/ && ls && exit"

test:
  stage: test
  script:
    - echo "Testing..."

我刚刚在要推送到的服务器上创建了一个ssh密钥,然后将私钥作为git-lab变量添加到git-lab服务器,然后在脚本.gitlab-ci中使用了它,但确实在任何地方都没有添加任何公钥,我得到了错误:

  

user @ ip:权限被拒绝(公钥)。

在构建阶段,请提供任何帮助,并在此先感谢

1 个答案:

答案 0 :(得分:1)

您需要将公用密钥添加到 <Accordion alwaysOpened title='Personal info'> <Text >Personal info screen will be here</Text> </Accordion> 上的/home/user/.ssh/authorized_keys上,这基本上会告诉服务器授权使用用户名$DEPLOY_SERVER通过ssh通过服务器访问哪些公用密钥

相关问题