openssl: Error loading key ".ssh/id_rsa": error in libcrypto
Hi, im using my ssh RSA key for many years. After update to openssl3 i noticed an issue:
[tpg@tpg-virtualbox .ssh]$ ssh-add
Error loading key "/home/tpg/.ssh/id_rsa": error in libcrypto
I’ve validated my keys: [tpg@tpg-virtualbox .ssh]$ ssh-keygen -l -f id_rsa.pub 4096 SHA256:hereisthehash xxx@gmail.com (RSA)
Newly generated key with ssh-keygen works.
I tried to generate RSA key with openssl:
[tpg@tpg-virtualbox .ssh]$ openssl genrsa -des3 -out private.pem 2048
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
[tpg@tpg-virtualbox .ssh]$ openssl rsa -in private.pem -outform PEM -pubout -out public.pem
Enter pass phrase for private.pem:
writing RSA key
[tpg@tpg-virtualbox .ssh]$ openssl pkey -check -in private.pem -noout
Enter pass phrase for private.pem:
Key is valid
[tpg@tpg-virtualbox .ssh]$ openssl pkey -pubcheck -in public.pem -noout
Could not read key from public.pem
Unable to load key
My system is OpenMandriva Cooker
[tpg@tpg-virtualbox .ssh]$ rpm -qa | grep openssl
openssl-3.0.0-0.alpha8.1.x86_64
[tpg@tpg-virtualbox .ssh]$ rpm -qa | grep openssh
openssh-8.4p1-2.x86_64
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 46 (14 by maintainers)
I got this error message with a private key that had been copy pasted as text. It turns out that the file must end with a new line for it to work.
This occurred for me as I had an IdentityFile directive in ~/.ssh/config which was pointing to my public key. Changing it to point to the private key fixed the “error in libcrypto”. Would be great if this error message was more specific.
I got this error message when using
ssh-keygen -t ed25519to create my key but not when usingssh-keygen(no options).@mattcaswell if you help me how to debug this i’ll provide needed information:
cat private.pem
cat id_rsa
If you are on Windows, and you do have newline in the end of the file, but you still get the error, then try to convert it to Unix-style, for example with
dos2unix:That fixed it in my case.
I just verified
ssh-addwithopenssl-3.0.0-alpha16and now it WORKS ! Thanks!Not sure how this is related to the original issue. It should be reported as separate issue ideally with some reproducer cut out of the FreeRDP code. Otherwise it would be really hard to find the cause.
There is something wrong with openssh in Openmandriva, this issue happened for me as well. I am using their rolling repo.