Load pubkey “/path/to/private.key”: invalid format when using SSH

Been hitting the lottery with system upgrade related issues as of late. The
latest come in the form of ssh barking about an invalid public key when
connecting to a server.

This wasn’t happening on all of my servers, just one in particular.

Also, it wasn’t actually stopping me from connecting, it was just letting me
know that it was running into an issue. I suspect that perhaps this is
intermediary behavior and down the road this would cause a full stop when trying
to connect.

The error I was running into (as the title suggests) was:

load pubkey "/home/josh/.ssh/server.id_rsa": invalid format

Since it wasn’t happening on every connection, I started to compare my keys to
see if there was something noticeable in the offending key that was causing the
error.

I should mention, I was checking the private keys, even though the error
explicitly mentioned pubkey.

DERP

All right then, I repeated the same process but this time with the public keys.

Except I didn’t have a public key to match that particular private key for that
server. Usually I don’t even keep public keys for keys other than my primary
personal key to alleviate the scenario where ssh-copy-id copies all of your
public keys to a server.

Since evidently this is a requirement now, or there’s some setting out there for
my ~/.ssh/config that I couldn’t dig up in the man pages, I just ended up
generating a public key for the private key in question.

To generate a public key:

ssh-keygen -y -f server.id_rsa > server.id_rsa.pub

Not much to it, that command will generate the public key and make sure it has
the write permissions and ssh should shut up about the alleged “invalid
format”.

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.