How to extract public key using OpenSSL?

Jake picture Jake · Apr 22, 2012 · Viewed 175.5k times · Source

The following command generates a file which contains both public and private key:

openssl genrsa -des3 -out privkey.pem 2048

Source: here

With OpenSSL, the private key contains the public key information as well, so a public key doesn't need to be generated separately

How can we extract the public key from the privkey.pem file?

Thanks.

Answer

stewe picture stewe · Apr 22, 2012
openssl rsa -in privkey.pem -pubout > key.pub

That writes the public key to key.pub