OpenSSL 3 · Certificates
Check that a key matches a certificate
Compare the public key hashes of a certificate and a private key. They must be identical.
openssl x509 -in cert.pem -noout -pubkey | openssl sha256
openssl pkey -in private.key -pubout | openssl sha256
Official OpenSSL 3 documentation