How to get ssh public key from private key
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
-