id_rsa.pub is not a public key file

12,785

You might not open this file using complex text editor. Use Notepad++ or gedit (something like this) to edit your file.

Then, verify you have a space between 'ssh-rsa' and "AAAA....." at the beginning of your key.

To regenerate your public key, use the -y option as follow :

ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub

I hope it will fix your problem :)

From man ssh-keygen:

-y      This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.

Source : serverfault.com

Share:
12,785
Dobob
Author by

Dobob

Updated on June 14, 2022

Comments

  • Dobob
    Dobob almost 2 years

    I opened my public key in libre office and edited the comment section of the key and then saved. But when I run:

    ssh-keygen -l -f id_rsa.pub 
    

    I get:

    id_rsa.pub is not a public key file.
    

    The file is no longer recognized as a public key file. How do I solve this?

    • Magic-Mouse
      Magic-Mouse over 7 years
      Open the file in Notepad++ and check that libre office didn't change the formatting it is easy for programs like word and libre office to change formatting on documents and even change characters like ' in to ` just to give an example. They also tend to add random linebreaks in to files.
    • Dobob
      Dobob over 7 years
      I didn't back up the key, so I can't compare.
    • Scott Stensland
      Scott Stensland over 2 years
      delete any blank lines both before and after the populated lines of the ssh key file ... doing this fixes one source of getting that message : is not a public key file.