How to Generate a Public Key from a Private Key

Recently, I needed to find the corresponding public key from a private key (.pem) to give a Linux user access to a server. I used the below code to generate the public key.

ssh-keygen -y -f privatekey > publickey

This code generates an OpenSSL key, which wasn't what I needed in that specific case, but might also come in handy.

openssl rsa -in privatekey -pubout > publickey
Tania

About the author

Hey, I'm Tania, a software engineer, writer, and open-source creator. I publish guides and tutorials about modern JavaScript, design, and programming.

Join newsletterBuy me a coffee