How do I get the public key of a pem file?

Solution 1:

On Linux:

ssh-keygen -f private.pem -y > public.pub

On macOS:

ssh-keygen -f Private.pem -y | pbcopy

Note that if your permissions are vague on the .pem file, then ssh-keygen will generate an empty .pub file.

You can usually fix this with:

chmod 400 private.pem 

Solution 2:

JazzCat's answer works. small addition: if your permissions are vague on .pem file, ssh-keygen will generate empty .pub file.

if you see any complains on terminal about private key too open, try to narrow it using chmod 400 private.pem and retry above command.

ps: sorry I don't have permissions to add a comment instead of answer.