Verify if a private key matches a certificate with openssl

For this compare the modulus of the public key in the certificate against the modulus of the private key:

openssl rsa -modulus -noout -in myserver.key | openssl md5
openssl x509 -modulus -noout -in myserver.crt | openssl md5