When you install an SSL certificate and the server refuses to start — or throws an "SSL_CTX_use_PrivateKey_file: key values mismatch" error — the most likely cause is that the private key and certificate are not a matched pair. This happens when a certificate is renewed or reissued but the old private key file is left in place, or when files are accidentally mixed up across multiple domains.
Works on all platforms: All OpenSSL commands in this guide work identically on Linux, macOS, and Windows. See the installation notes below for your OS.
Installing OpenSSL (All Platforms)
# Linux (Debian/Ubuntu)
sudo apt install openssl
# Linux (RHEL/CentOS/Fedora)
sudo dnf install openssl
# macOS (uses LibreSSL by default, or install full OpenSSL)
brew install openssl
# Then use: /opt/homebrew/opt/openssl/bin/openssl
# Windows — install via winget:
winget install ShiningLight.OpenSSL
# Or via Chocolatey:
choco install openssl
# After installing, 'openssl' is available in Command Prompt and PowerShell
Check if Your Key and Certificate Match (RSA)
The fastest way to confirm a match: compare the MD5 hash of the modulus from both files. If the hashes are identical, the key and certificate are a pair. Run these commands in Terminal (Linux/macOS) or Command Prompt/PowerShell (Windows — same syntax):
Also Check the CSR Modulus (If You Still Have It)
# All three should have the same modulus hash:
openssl rsa -noout -modulus -in yourdomain.key | openssl md5
openssl req -noout -modulus -in yourdomain.csr | openssl md5
openssl x509 -noout -modulus -in yourdomain.crt | openssl md5
# If the key and CSR match but the cert doesn't, the CA issued the cert
# against a different CSR — you need to reissue with the correct CSR.
ECC Keys: Public Key Comparison Method
ECC (ECDSA) keys don't have an RSA modulus. For ECC, compare the public key extracted from the private key against the public key in the certificate:
# Extract public key from ECC private key:
openssl ec -in yourdomain-ecc.key -pubout 2>/dev/null | openssl md5
# (stdin)= 7c4b9f2e...
# Extract public key from ECC certificate:
openssl x509 -in yourdomain.crt -pubkey -noout | openssl md5
# (stdin)= 7c4b9f2e... ← must match
# One-liner that tells you directly:
KEY=$(openssl ec -in yourdomain-ecc.key -pubout 2>/dev/null | openssl md5)
CRT=$(openssl x509 -in yourdomain.crt -pubkey -noout | openssl md5)
[ "$KEY" = "$CRT" ] && echo "MATCH" || echo "MISMATCH"
What to Do When There's a Mismatch
Never regenerate the private key if you still need the existing certificate. The private key must match the specific public key in the certificate — a new key means the certificate is useless.
If the key and cert don't match, you have two options:
- Find the correct private key — search your server for files with a matching modulus hash. The key may be in a different directory or named differently.
- Reissue the certificate — generate a new key + CSR, submit the CSR to your CA, and install the newly issued certificate with the new key.
# Find all .key files on the server and check which one matches your cert:
CERT_MOD=$(openssl x509 -noout -modulus -in yourdomain.crt | openssl md5)
find /etc /var/www /home -name "*.key" 2>/dev/null | while read keyfile; do
KEY_MOD=$(openssl rsa -noout -modulus -in "$keyfile" 2>/dev/null | openssl md5)
if [ "$KEY_MOD" = "$CERT_MOD" ]; then
echo "MATCH FOUND: $keyfile"
fi
done
Windows alternative — PowerShell: You can also verify a key/cert match using PowerShell's built-in .NET crypto classes, without OpenSSL:
# PowerShell key/cert match check (Windows)
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("yourdomain.crt")
$rsa = [System.Security.Cryptography.RSA]::Create()
$rsa.ImportFromPem((Get-Content "yourdomain.key" -Raw))
$certKey = $cert.GetPublicKey()
$pubFromPriv = $rsa.ExportSubjectPublicKeyInfo()
if ([System.Linq.Enumerable]::SequenceEqual($certKey, $pubFromPriv)) {
Write-Host "MATCH — key and certificate are a pair"
} else {
Write-Host "MISMATCH — key and certificate do NOT match"
}
The modulus comparison method is safe — it never reveals the private key's secret material. The modulus is the public component of the RSA key pair, and its MD5 hash is safe to compute and compare.
Verify your SSL installation in the browser
Our SSL checker confirms your certificate, chain, and key are all correctly installed on the server.