When I am trying to generate a public key it still gives me an error "error in libcrypto"

Load key "breakthis": error in libcrypto

Private key is given below

I am trying to solve a Hack the box machine

I was able to get a private key then I converted that private key into a hash for JOHNTHERIPPER and cracked it successfully

But now when I try to login in through ssh I am getting the following error I have searched a lot but not able to resolve these error

ssh -i id_rsa [email protected]

load pubkey "id_rsa": invalid format 

Load key "id_rsa": error in libcrypto

[email protected]'s password: 

  • 3
    I am still getting an error "error in libcrypto" Apr 2, 2020 at 11:13
  • Update your question with how you are attempting to connect after generating the public key from the private key. Apr 2, 2020 at 12:46
  • As mentioned by Alex, a using a public key in ~.ssh/.config seems to cause cause the error in libcrypto for me as long as that key is not loaded by a running SSH agent. It happened for me when my keeagent crashed. However, restarting the agent seems to allow such setup as mentioned in here
    – kf06925
    Jan 6, 2023 at 14:42
  • 1
    @NasirRiley Your statement is wrong. I am simply correcting the wrong information. End of the conversation.
    – Drew
    Jan 28, 2023 at 5:40
  • 3
    Just to clear up confusion for anyone stumbling across this comment chain, the private key is indeed what you need to connect each time. As proof, try ssh -i ~/.ssh/id_rsa.pub (or equivalent) and see what happens. You need ssh -i ~/.ssh/id_rsa. You can use the file command on the key files to see what kind of key they are. Indeed, the server needs your public key in its known_hosts for you to connect, but that is a one-time operation and is not a routine part of establishing SSH connections to a server.
    – eeowaa
    Jun 13, 2023 at 19:17

8 Answers 8


In my case I had copied the keyfile using the clipboard, which had created a similar file but without terminating newline. That was enough to trip up libcrypto. Opening the file in vim and :wq closing it, was enough to add the newline, and it fixed my issue.

  • 6
    haha this is such a stupid issue, surely it is a bug? why would a newline at the end of the file be a hard requirement Feb 19, 2023 at 19:38
  • Mine was a different problem... but replacing every "\n" with actually "enter" in nano editor has solved my problem. :-)
    – Manan Shah
    Jun 1, 2023 at 6:25
  • I had a similar issue caused by copying to the clipboard - the issue was my pasted file then had Windows CRLF line endings. The solution was to convert to Unix LF line endings (which can be done in Sublime Text)
    – pjpscriv
    Oct 20, 2023 at 4:46
  • No success with vim, but I used dos2unix .ssh/id_keyfound and it worked
    – Kantium
    Nov 29, 2023 at 21:15
  • This reminded me to wrap my ssh key in base64 format in gitlab-ci variable. Hope it helps someone.
    – Fedcomp
    Dec 12, 2023 at 14:23

ERROR: load pubkey "id_rsa": invalid format

It happens when public key is used in ~/.ssh/config instead of using private key.


I fixed the Load key "id_rsa": error in libcrypto error by adding an LF control character (new line) at the end of the last line -----END OPENSSH PRIVATE KEY----- of the .pem file.

Before (doesn't work):

enter image description here

After (works):

enter image description here

Note the additional LF control character in the last non-empty line. One can add an LF control character by simply hitting the ENTER key.

Commands used to SSH into my remote computer:

chmod 400 key.pem
ssh -i "key.pem" [email protected]

Note: the error message can be either:

  • Load key "id_rsa": error in libcrypto (I saw it on my Ubuntu computer).
  • Load key "key.pem": invalid format (I saw it on my Windows computer) .

To show End of Line control characters in Notepad++:

enter image description here

  • 1
    This is the answer if you are coming here from GitLab CI. As a File variable it will truncate the trailing newline. Adding a simple extra newline in the variable solves the issue.
    – Jeff Mixon
    Jan 19 at 21:07

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:

    - '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'
  • this helped me so very much - thanks !!!!!!
    – Datum Geek
    Mar 11 at 7:08

I got this error, when I was using 2 github accounts with 2 ssh keys, but get rid of this error when i changed my config file like below,

myDir$ ssh -T [email protected]
Load key "/home/taxi/.ssh/mhmd_personal.pub": error in libcrypto
[email protected]: Permission denied (publickey).

From this

Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/mhmd_personal.pub
  # IdentityFile ~/.ssh/id_ed25519


Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/mhmd_personal
  # IdentityFile ~/.ssh/id_ed25519

removed the .pub extension from config file.

  • This does not fix the error.
    – nurettin
    Dec 24, 2022 at 8:20
  • some other git error may show similar error message, I am here to help Dec 26, 2022 at 6:11
  • Thank you @Md.SultanulArefin This was a life saver!
    – zsubzwary
    Dec 8, 2023 at 6:35

I just have fixed this problem. This problem was caused because of the format of the text.

Replace following the ssh-key format, Its looks like this:

  • 2
    For the next time; there's no need to do this manually. Command ssh-copy-id -i /pathto/privatekey user@remotehost will copy the corresponding public key in the correct format to the target :-) Mar 21, 2023 at 4:45

what fixed it for me was the answer to this question

I opened the key in puttygen then exported a new ppk using the conversion --> Export OpenSSH Key


So in my case the private key file was simply missing the read permissions for the owner. After adding the read permission (chmod u+r id_ecdsa), everything worked fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .