openssl: Load key "id_rsa": error in libcrypto

image

❯ uname -a
Linux BL4CK4RCH 6.1.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 14 Jan 2023 13:09:35 +0000 x86_64 GNU/Linux

all help are welcome to fix that. Regards.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Hey guys, for future readers. I was using a ssh key file inside Gitlab CI YAML file and I kept getting error in libcrypto message. I did 2 things that FIXED the problem:

  1. Just changing the variable type from FILE variable to ENV_VAR
  2. Using ssh-keygen -t ed25519 when generating the key. Looks like gitlab does not support the default rsa keys.

Then everything works fine.

Also use this as the base before_script:

  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client wget gnupg -y )'
    - wget -qO- https://get.docker.com/gpg | apt-key add -
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - touch ~/.ssh/config
    - touch ~/.ssh/known_hosts
    - chmod -R 400 ~/.ssh
    - ssh-keyscan <ip> >> ~/.ssh/known_hosts
    - '[[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

Answering here for another use case just because it was top result with this problem. I was facing this same error and it was due to some extra carriage return character i.e. ‘\r’, in the file. I was coping the private key from a variable store and saving it into the machine using python. I replaced the ‘\r’ with null character using the code below and the issue was resolved.

private_key = variable.get('private_key')
with open('./file', 'w+') as f:
    f.writelines(private_key.replace('\r',''))

I use kali on WSL also has this problem。

$ uname -a
Linux 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 GNU/Linux

$ openssl version
OpenSSL 3.1.4 24 Oct 2023 (Library: OpenSSL 3.1.4 24 Oct 2023)

oh!!!I solve it ,It’s all my fool…

This is most likely an issue with the file format, as above.

but my fault is : my ssh config file set IdentityFile wrong。

right:IdentityFile ~/.ssh/id_ed25519 wrong: IdentityFile ~/.ssh/id_ed25519.pub

Answering here for another use case just because it was top result with this problem. I was facing this same error and it was due to some extra carriage return character i.e. ‘\r’, in the file. I was coping the private key from a variable store and saving it into the machine using python. I replaced the ‘\r’ with null character using the code below and the issue was resolved.

private_key = variable.get('private_key')
with open('./file', 'w+') as f:
    f.writelines(private_key.replace('\r',''))

I also had this problem. Make sure when pasting keys anywhere you don’t have an empty line at the end. This borked my github actions.

nvm the probleme was the key bad format. it working as exept now, i was thinking got another error message before when key as bad format? thx for the help. Regards