gitlabRunner ssh私钥644文件权限错误

时间:2020-10-06 21:14:41

标签: ssh gitlab gitlab-ci-runner

在运行gitlab ci / cd管道时,ssh会给出0644错误的权限错误。变量作为文件类型存储在gitlab的settings> variable部分中。
.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。

1 个答案:

答案 0 :(得分:1)

您可以在此deploy processgitlab-ci.yml中看到相同的错误

fixed version of that file

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就足够了。