SSH Suddenly returning Invalid format
Solution 1:
Starting openssh 7.6, it defaults to a new more secure format. You can force it to convert to that format using the commands below to change your key password. In case you don't have and/or don't want a password, you can simply press enter and it will still rewrite the key in the new format
ssh-keygen -f ~/.ssh/id_rsa -p
Solution 2:
Check the contents of key_name
, if the agent says invalid format
, then there's something wrong with the key - like .. are you sure that's the correct key? Even if it's not the private key you need, the ssh agent won't return invalid format
if the key is working, you simply won't be able to connect. You might have placed your public key in there, for some reason. Check it!
Solution 3:
I had the same issue, and it turns out I had Windows-style (CRLF) line separators in the file for some reason.
In addition, the file must end with a single LF.
Fixing those made things dandy again.
Solution 4:
What i did to fix this issue is that i use to convert the PPK file using PuttyGen
.
First load the urkey.PPK
, then on the conversion menu, click export to Openssh file format. It will create newkey file.
now, ssh -i "newkey" [email protected]
Done. Hope it helps.
Solution 5:
If you get a warning about an invalid public key format but the command still works then it may be because you only have a private key file and are using OpenSSH 8.3.
OpenSSH 8.3 includes a change to the ssh client where it looks for the private key's corresponding public key file and outputs this load pubkey "/home/user/.ssh/id.rsa": invalid format
warning but continues to connect successfully. Tools using ssh, such as scp
or git
may show key_load_public: invalid format
.
The client does not need the public key when connecting, only the private key. So this check is pointless and it has already been removed by an upstream commit but isn't in a relase (yet).
There's a discussion about this on the ArchLinux forum.