ssh: Error loading key "./id_rsa": invalid format
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Drifting Through My Dreams
--
Chapters
00:00 Ssh: Error Loading Key &Quot;./Id_rsa&Quot;: Invalid Format
00:51 Accepted Answer Score 26
02:42 Answer 2 Score 12
02:59 Answer 3 Score 3
03:22 Answer 4 Score 5
03:40 Thank you
--
Full question
https://superuser.com/questions/1370877/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #ssh #sshagent
#avk47
ACCEPTED ANSWER
Score 26
Traditionally OpenSSH used the same private key format is identical to the older PEM format used by OpenSSL. (Because it uses OpenSSL for parsing the key, it will accept the newer PKCS#8 format as well.)
So the issue can be one of:
Your OpenSSL version refuses to load this key format. Perhaps it has accidentally enabled FIPS mode and refuses any algorithms except those part of its original FIPS validation?
Try loading the key into the
openssl
command-line tool (which, yes, might also be linked to a different libcrypto, and you should check with ldd):openssl rsa -noout -text < id_rsa openssl pkey -noout -text < id_rsa
Try converting it to PKCS#8 format:
umask 077 openssl pkey < id_rsa > id_rsa.pkcs8 ssh-add id_rsa.pkcs8
Your OpenSSH has been built without OpenSSL support. Even though
ssh -V
says the support was enabled, that does not automatically mean thessh-add
binary is the same – it might come from a different partial installation.Use
type -a ssh
andtype -a ssh-add
to compare installation locations.Once you know the path, use
ldd /usr/bin/ssh-add
to verify that it's linked tolibcrypto.so
(the OpenSSL cryptographic library).
If nothing works at all, try converting your key to the new OpenSSH-proprietary format using... PuTTY. Install the putty
package for Fedora, and use:
puttygen id_rsa -o id_rsa.newformat -O private-openssh-new
ssh-add id_rsa.newformat
Also peculiar: GNOME somehow manages to add the key on login with seahorse.
Older GNOME Keyring versions have an internal copy of the SSH agent code and are independent from the system OpenSSH. So they will accept keys that your OpenSSH won't. (But on the other hand, this means severe lagging in terms of feature support (such as Ed25519 keys), and the latest GNOME Keyring just uses the system ssh-agent instead.)
ANSWER 2
Score 12
In my case, the problem was caused by incorrect end of line characters in id_rsa file. After copying file content, Windows text editor wanted to help me and converted EOLs to CR LF.
ANSWER 3
Score 5
In my case, I just copied id_rsa private key but not the public part id_rsa.pub. It worked but complained with 'invalid format' each time I did server operations. Copying id_rsa.pub as well solved the problem.
ANSWER 4
Score 3
I recently had this problem, and in my case it was due to having an invalid certificate (i.e. $HOME/.ssh/id_rsa-cert.pub
), which confusingly gave this same error even though my private key was still valid and SSH continued to work.
It was fixed by either removing the invalid (in my case, zero-sized) cert file, or replacing it with a valid certificate, as the case may be.