Tania Rascia

Skip Navigation
How to Generate a Public Key from a Private Key

How to Generate a Public Key from a Private Key

 /  Leave a response

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

Newsletter

Get updated when I create new content.
Unsubscribe whenever. Never any spam.

Note

I'm Tania. I turn down every ad, affiliate, and sponsor request I get. I write free resources that help thousands of people successfully become devs. If you enjoy my content, please consider supporting what I do.

Support my work

Write a response

Your email address will not be published. Required fields are marked *

All code will be displayed literally.