I'm trying to add a SSH key to a GitLab pipeline. The SSH key is in ED25519 format and saved as a group environmental variable and as a file in GitLab. When I saved the contents of the SSH key in GitLab I hit 'return' to add another line. When I try to load the SSH key into a pipeline I get Error loading key "(stdin)": error in libcrypto. I also tried manually adding a new line in the pipeline YAML by using echo >> "$PIPELINE_SSH_KEY" but got the same error. I'm following what is recommended in the GitLab documentation about adding a newline but it doesn't work. Do I need to add the newline in a different way?
Here's part of my GitLab YAML:
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- eval $(ssh-agent -s)
- echo >> "$PIPELINE_SSH_KEY"
- echo "$PIPELINE_SSH_KEY" | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $CI_SERVER_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
I had that error because file with private key was not ended with the new line. Once I have added new line to the end of the file - problem has gone.
I figured out the issue. I added the wrong key. I added the public key when it should have been the private key. Once I added the private key and added the bash commands shown in this GitLab documentation page in step 3: https://docs.gitlab.com/ee/ci/ssh_keys/#troubleshooting, everything worked. I had to add the public key as a deploy key in GitLab as described here: https://docs.gitlab.com/ee/user/project/deploy_keys/#create-a-public-deploy-key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With