Can we generate a public key from a private key?
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_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
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.