Wednesday, August 31, 2022

[SOLVED] id_rsa.pub is not a public key file

Issue

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?


Solution

  1. You should not open this file using complex text editor. Please use Notepad++, gedit (or any equivalent) to edit your file.

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

If you don't see anything wrong with the file and it still doesn't work, you can regenerate your public key.
Use the -y option as following:

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



Answered By - Kapcash
Answer Checked By - Senaida (WPSolving Volunteer)