14

UPDATED

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: 

11
  • 1
    You are supposed to use the public key to connect via ssh, not the private key. You need to generate a public key from the private key. The accepted answer here will show you how: serverfault.com/questions/52285/…. Apr 2, 2020 at 4:13
  • 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
  • 1
    @NasirRiley Your statement is wrong. I am simply correcting the wrong information. End of the conversation.
    – Drew
    Jan 28 at 5:40
  • 2
    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 at 19:17

8 Answers 8

18

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.

4
  • 3
    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 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 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 at 4:46
  • No success with vim, but I used dos2unix .ssh/id_keyfound and it worked
    – Kantium
    Nov 29 at 21:15
14

ERROR: load pubkey "id_rsa": invalid format

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

5

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

0

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

to

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

removed the .pub extension from config file.

3
  • 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
    yesterday
0

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:

-----BEGIN OPENSSH PRIVATE KEY-----
ENCODED KEY DATA HERE
-----END OPENSSH PRIVATE KEY-----
1
  • 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 at 4:45
0

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'
0

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

0

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 .