Search code examples
sshgitlabgitlab-cissh-keysprivate-key

GitLab WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0660 for '/dev/fd/63' are too open


I use GitLab for CI/CD and I would like to ssh to my Raspberry Pi for deployment. I generated a new ED25519 SSH key pair, added the private key to variables and the pubic key to deploy keys.

My gitlab-ci.yaml file looks like this:

deployment:
    stage: deploy
    before_script:
      - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
      - mkdir -p ~/.ssh
      - chmod 700 ~/.ssh
      - eval $(ssh-agent -s)
      - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
      - ssh-add <(echo "$SSH_PRIVATE_KEY")
      - apt-get install rsync
    script:
      - ssh pi@IP-ADDRESS "cd dockerproject2 && mkdir test"
    tags:
      - ssh

This is the output of my deployment stage:

$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ eval $(ssh-agent -s)
Agent pid 2805
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0660 for '/dev/fd/63' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
ERROR: Job failed: exit status 1

I tried to change the permission of the private key with $ chmod 600 private_key_nameand with $ chmod 0644 private_key_name. I restarted the Raspberry Pi afterwards. But nothing worked.


Solution

  • I have found a solution.

    It is just don't possible to use this command like this: ssh-add <(echo "$SSH_PRIVATE_KEY")

    It has to look like this: echo "$SSH_PRIVATE_KEY" | ssh-add -