5

Can we generate a public key from a private key?

closed as unclear what you're asking by Gilles, Rory Alsop Sep 1 '14 at 15:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • ... for what PKE scheme? – user49075 Sep 1 '14 at 5:19
  • In RSA, and in normal implementations, yes you can. – Adi Sep 1 '14 at 5:48
  • 3
    Hello and welcome to security.se. When asking question, please take the time to specify all relevant information. In it's current state, your question is impossible to answer. – Stephane Sep 1 '14 at 7:29
  • Also see: Given a private key, is it possible to derive its public key? on StackOverflow. – sleske Sep 1 '14 at 9:09
7

By default, a user’s SSH keys are stored in that user’s ~/.ssh directory. You can check if your private key is in that directory by listing the contents:

$ cd ~/.ssh
$ ls
authorized_keys2  id_dsa       known_hosts
config            id_dsa.pub

The private key is usually something like id_dsa or id_rsa. To regenerate the public key part with just a private key, use the -y switch to the ssh-keygen application and write the output to a corresponding .pub file:

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

From the 'man ssh-keygen' description:

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

If you don't know whether your private key is Digital Signature Algorithm (DSA) or Rivest Shamir Adleman (RSA), you will have to use the ssh-keygen application with the -f switch. Make sure the name of your new public key matches the name of your private key.

Not the answer you're looking for? Browse other questions tagged or ask your own question.