How to extract public key from certificate?

How to extract public key from certificate?

Recently I had to extract the public key from a certificate. Each time I do this I end up looking up the man pages for openssl and so I thought I’d blog it for myself and for others to use when needed.

$ openssl x509 -inform pem -in certificate.pem -pubkey -noout > publickey.pem

Enjoy