GrepBoard/Manuals
605 manuals ·

Fix HAProxy unable to load SSL private key from PEM file

·Tested on HAProxy 3.4.7 (Docker) · OpenSSL 3.5.7 · 2026-10·Test scope ↓·6 steps

HAProxy can't load the private key (3.x says No Private Key found)? Check the key is in the crt file, then its pair, passphrase and PEM lines.

output
[ALERT]    (12) : config : parsing [/w/h.cfg:9] : 'bind :8443' in section 'frontend' : No Private Key found in '/w/a/site.pem.key'.

HAProxy could not find a private key for the file given to bind … ssl crt. Old releases (1.5 and similar) reported this as unable to load SSL private key from PEM file, followed by no SSL certificate specified for bind; 3.4 says No Private Key found as above. Most of the time the crt file holds only the certificate, or the PEM file is malformed.

Unlike nginx, HAProxy's crt has no separate key directive. Put the certificate and the private key in one file, or place a <file name>.key next to it.

[1] Run a config check to see the exact message and file. It does not affect the running HAProxy.

console
# haproxy -c -f /etc/haproxy/haproxy.cfg

[2] Map the message to a cause. These came from the official 3.4.7 image, one case each.

Message in 3.4Cause
No Private Key found in '…/site.pem.key'the file has a certificate but no key
Trying to load a passphrase-protected private key without an 'ssl-passphrase-cmd' defined.the key is encrypted
inconsistencies between private key and certificate loadedthe key belongs to another certificate
unable to load certificate from file '…': bad end line.an END line and the next BEGIN line are glued together

[3] Look at what the file contains. It needs at least one certificate block and one key block.

console
# grep -E '^-----' /etc/haproxy/certs/site.pem
output
-----BEGIN CERTIFICATE----------END CERTIFICATE----------BEGIN PRIVATE KEY----------END PRIVATE KEY-----

No BEGIN PRIVATE KEY (or RSA PRIVATE KEY, EC PRIVATE KEY) means the key is missing. BEGIN ENCRYPTED PRIVATE KEY means it has a passphrase. A line like -----END CERTIFICATE----------BEGIN … means the previous file had no trailing newline. In the test, the same file converted to Windows line endings (CRLF) passed without error.

[4] If the key is there and you get inconsistencies, compare the public key hashes.

console
# echo "cert: $(openssl x509 -in site.pem -noout -pubkey | openssl sha256)"# echo "key : $(openssl pkey -in site.pem -pubout 2>/dev/null | openssl sha256)"
output
cert: SHA2-256(stdin)= dda1e613244a1ce8929e52742a8d354097f500672d6e39648264936bc41b5cffkey : SHA2-256(stdin)= 910b72ac6b1ea0c60d7d555609289109b93bb1ee7b4d501817c10290543fb952

Different hashes mean you need the key the certificate was issued for. The same check for nginx is in nginx key values mismatch.

[5] Rebuild the file. Keep the original, build a new file, and swap it in once the check passes.

console
# cat example.com.crt intermediate.crt example.com.key > /etc/haproxy/certs/site.pem.new# chmod 600 /etc/haproxy/certs/site.pem.new# openssl x509 -in /etc/haproxy/certs/site.pem.new -noout -subject# mv /etc/haproxy/certs/site.pem /etc/haproxy/certs/site.pem.bak# mv /etc/haproxy/certs/site.pem.new /etc/haproxy/certs/site.pem# haproxy -c -f /etc/haproxy/haproxy.cfg

To keep the key separate, name it after the full certificate file name plus .key (site.pem.key next to site.pem). In the test both layouts made haproxy -c exit with 0.

For an encrypted key, set ssl-passphrase-cmd in global to a command that prints the passphrase, or switch to an unencrypted key — in which case file permissions are its only protection.

[6] Reload only after the check passes.

console
# systemctl reload haproxy

Analyze your HAProxy log in the browser ↗ — nothing is uploaded.

Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.

#haproxy#ssl#pem#certificate