Skip to content

Instantly share code, notes, and snippets.

@jesugmz
Last active December 2, 2022 23:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesugmz/03951b52e9777edf2d4aed62cf003273 to your computer and use it in GitHub Desktop.
Save jesugmz/03951b52e9777edf2d4aed62cf003273 to your computer and use it in GitHub Desktop.
Solve load pubkey "/root/.ssh/id_rsa": invalid format

OpenSSH 8.3p1 introduces the need of having a public SSH key otherwise is gonna show the warning

load pubkey "/root/.ssh/id_rsa": invalid format

# ssh -V
OpenSSH_8.3p1, OpenSSL 1.1.1g  21 Apr 2020

To supress this message we can put in place our SSH public key or generate it from our private key with:

# ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub

As pointed out in https://bbs.archlinux.org/viewtopic.php?id=256210 there is already a commit ready to fix this in the future.

@vee-varun
Copy link

I am getting this warning in OpenSSH_7.9p1. I have both private and public keys in the same place. Any Idea, what to do?

@jesugmz
Copy link
Author

jesugmz commented Sep 19, 2020

I am getting this warning in OpenSSH_7.9p1. I have both private and public keys in the same place. Any Idea, what to do?

That message should be for version 8.3p1, anyway, I would check permissions. OpenSSH is very sensible to them.

@FelikZ
Copy link

FelikZ commented Nov 24, 2020

For me it was due to newer private key format, which generates:

-----BEGIN OPENSSH PRIVATE KEY-----
...

To fix this, I have regenerated file using -m pem option:

ssh-keygen -t rsa -b 4096 -m pem

@sumitpal-singh
Copy link

For me it was due to newer private key format, which generates:

-----BEGIN OPENSSH PRIVATE KEY-----
...

To fix this, I have regenerated file using -m pem option:

ssh-keygen -t rsa -b 4096 -m pem

Your solution worked for me precisely. Thanks.

@LavaGolem
Copy link

Didn't work for me :(

@xjh1994
Copy link

xjh1994 commented Aug 12, 2021

Didn't work for me :(

Maybe you're using UTF8-bom. You can use sed -i 's/^\xEF\xBB\xBF//g' /root/.ssh/id_rsa to remove bom in the rsa file.
`

@aceqbaceq
Copy link

i ve had exactle the same error.

Load key "key_name": invalid format

I have solved it.

I suggest to check two things:

  1. if you are using ~/.ssh/config
    then pls check that you have specified there you PRIVATE key. If you specified publick key there - you ll get the error

  2. pls check your echo $HOME.
    in some OS like ubuntu\debian when you type:
    $ sudo bash
    your $HOME directory stay the same. I mean it is not /root
    so OS is looking for ssh keys in /home/user/.ssh/ dir!
    But you think it is using /root/.ssh dir
    so pls check echo $HOME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment