Let's suppose I have a SSH key, but I've deleted the public key part. I have the private key part. Is there some way I can regenerate the public key part?
2 Answers
Use the -y option to ssh-keygen:
ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub
From the 'man ssh-keygen'
-y This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.
Specify the private key with the -f option, yours might be dsa instead of rsa. The name of your private key probably contains which you used. The newly generated public key should be the same as the one you generated before.
- 8Why the "-t dsa"? Mayge the OP's key is rsa? I'd get rid of -t and instead use a -f.innaM– innaM2009-08-10 14:44:51 +00:00Commented Aug 10, 2009 at 14:44
- 2Good point, updated accordinglyKyle Brandt– Kyle Brandt2009-08-10 14:52:32 +00:00Commented Aug 10, 2009 at 14:52
- yeah mine originally was RSA.Amandasaurus– Amandasaurus2009-08-10 15:19:33 +00:00Commented Aug 10, 2009 at 15:19
- 1On Mac OSX 10.9.3 Mavericks I'm getting 'load failed' after running the command. How do I solve this?Hyperfocus– Hyperfocus2014-06-08 18:02:42 +00:00Commented Jun 8, 2014 at 18:02
- 1I think you might take this one step further with the -N parameter in case the private key is password protected:
ssh-keygen -f ~/.ssh/id_rsa -y -N "$PASSWORD" > ~/.ssh/id_rsa.pub
ken– ken2014-10-07 12:28:54 +00:00Commented Oct 7, 2014 at 12:28
Solution is specifically for users using Windows
Tool Used:
- Puttygen (PuTTY Key Generator)
- WinSCP
Steps to perform:
- Open PuTTY Key Generator.
- Load your private key (
*.ppk
file). - Copy your public key data from the "Public key for pasting into OpenSSH authorized_keys file" section of the PuTTY Key Generator and paste the key data to the "authorized_keys" file (using notepad) if you want to use it.
Snapshot showing portions of Puttygen to focus:
- Further reading: askubuntu.com/questions/53553/…devprashant– devprashant2015-11-21 10:07:21 +00:00Commented Nov 21, 2015 at 10:07
- 1Puttygen can also 'import' OpenSSH (really OpenSSL-legacy) and SSHCOM format privatekeys. And although originated on Windows, it has also been ported to Unix, and the Unix version of
puttygen
is a commandline (not GUI) program; see e.g. linux.die.net/man/1/puttygendave_thompson_085– dave_thompson_0852018-09-06 06:28:11 +00:00Commented Sep 6, 2018 at 6:28 - You cab get PuTTY and PuTTY tools on Linux too.mckenzm– mckenzm2023-11-14 23:32:44 +00:00Commented Nov 14, 2023 at 23:32