Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab runner ssh private key 644 file permission error

When running a gitlab ci/cd pipeline, ssh gives 0644 bad permission error. Variable is stored as a file type in the settings>variable section in gitlab.
.gitlab-ci.yml file looks like:

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"

Error:

$ 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

How do I change the private key permissions from 644 to 600 or 400.

like image 906
thecodeboxed Avatar asked Apr 21 '26 06:04

thecodeboxed


1 Answers

You can see the same error in this thread.

The 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

A simple chmod 400 $SSH_KEY should be enough.

like image 164
VonC Avatar answered Apr 26 '26 17:04

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!