Skip to content

Get public key from private key

homepage-banner

Using ssh-keygen command

The easiest way to get the public key from the private key is to use the ssh-keygen command. The ssh-keygen command is a tool for creating and managing SSH keys. To get the public key from the private key using ssh-keygen, you need to run the following command:

ssh-keygen -y -f private_key > public_key.pub

Here, private_key is the name of your private key file. The -y option tells ssh-keygen to generate the public key from the private key, and the > public_key.pub command redirects the output to a file named public_key.pub.

Using OpenSSL

Another way to get the public key from the private key is to use the OpenSSL command-line tool. OpenSSL is a robust, full-featured open-source toolkit implementing the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols, as well as a full-strength general-purpose cryptography library.

To get the public key from the private key using OpenSSL, you need to run the following command:

openssl rsa -in private_key -pubout > public_key.pub

Here, private_key is the name of your private key file, and the > public_key.pub command redirects the output to a file named public_key.pub.

Reference

  • https://stackoverflow.com/questions/5244129/use-rsa-private-key-to-generate-public-key
  • https://www.baeldung.com/linux/public-key-from-private-key
  • https://serverfault.com/questions/52285/create-a-public-ssh-key-from-the-private-key
  • https://docs.acquia.com/acquia-cloud-platform/manage-apps/command-line/ssh/getting-started/generate
  • https://8gwifi.org/pempublic.jsp
Feedback