Ubuntu – How to match a certificate file to a key file

apache-2.2sslssl-certificateUbuntu

I have a SSL certificate that the former sysadmin was issued (crt file.) Searching the filesystem I found several .key files. How do I match the crt to the key file and confirm that they match? This is Ubuntu Server 11.10 with Apache2 modssl.

Best Answer

Compare the modulus of the files.

Check the public key like this:

openssl x509 -in /path/to/cert.crt -noout -text

And check the private keys like this:

openssl rsa -in /path/to/cert.key -noout -text

Compare the "modulus" data (a big block of numbers) between the certificate and the potentially matching keys. If they match, then the key and certificate are a pair.