gitlab runner ssh私钥644文件权限错误

问题描述 投票:0回答:1

运行 gitlab ci/cd 管道时,ssh 给出 0644 badpermission 错误。变量作为文件类型存储在 gitlab 的“设置”>“变量”部分中。
.gitlab-ci.yml 文件如下所示:

stages:
  - deploy
  
before_script:
  - apt-get update -qq
  - apt-get install -qq git
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
deploy_1:
  stage: deploy
  only:
    - master
  tags:
    - master
  script:
    - ssh -i $SSH_KEY user@ip "mkdir -p runner_test"

deploy_2:
  stage: deploy
  only:
    - master
  tags:
    - master
  script:
    - ssh -i $SSH_KEY user@ip "mkdir -p runner_test"

错误:

$ ssh -i $SSH_KEY host@ip "mkdir -p runner_test"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/user/builds/gPnQDT8L/0/username/server.tmp/SSH_KEY' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/user/builds/gPnQDT8L/0/username/server.tmp/SSH_KEY": bad permissions
user@ip: Permission denied (publickey).
Cleaning up file based variables

如何将私钥权限从 644 更改为 600 或 400。

ssh gitlab gitlab-ci-runner
1个回答
4
投票

您可以在此线程中看到相同的错误。

该文件的固定版本:

server:
  stage: deploy
  script:
  - apt-get install -y openssh-client rsync
  - chmod 400 $SSH_KEY
  - scp -o StrictHostKeyChecking=no -P $SSH_PORT -i $SSH_KEY public/server.zip $SSH_URI:modpack/server.zip

一个简单的

chmod 400 $SSH_KEY
就足够了。

© www.soinside.com 2019 - 2024. All rights reserved.