curl: (58) unable to set private key file / could not load PEM client certificate
curl couldn't load the client certificate or its private key for mutual TLS.
curl: (58) unable to set private key filecurl: (58) could not load PEM client certificateunable to set private key file: 'client.key' type PEMcurl: (58) NSS: client certificate not foundcould not load PEM client certificate, OpenSSL error Meaning
The cert and key must match, be PEM (or use --cert-type), and the key password (if encrypted) must be supplied (--pass). Use --cert file.pem --key key.pem, avoid combining files in the wrong order, and check permissions.
Common causes
- Cert and key don't match
- Wrong file format/type
- Encrypted key without
--pass - File not readable
- PKCS#12 used without
--cert-type P12
⚡ Quick fix
- Verify the pair: compare
openssl x509 -modulusandopenssl rsa -modulus - Pass
--cert-type P12for PFX - Use
--passfor encrypted keys
Detailed fix by platform
Shell
- bash
curl --cert client.pem --key client.key --cacert ca.pem https://mtls.example.com/ curl --cert-type P12 --cert client.p12:password https://mtls.example.com/
How to diagnose
- Pair — Matches?
- Type — PEM/P12?
- Passphrase — Supplied?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SSL / TLS
- HTTPSConnectionPool: Max retries exceeded (SSLError) Python requests: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /v1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] ...')))
- DST Root CA X3 expired (old clients fail) Old clients: certificate has expired — Let's Encrypt chain uses expired DST Root CA X3 (OpenSSL 1.0.x, Android < 7.1.1)
- Keystore was tampered with, or password was incorrect Java keytool: java.io.IOException: Keystore was tampered with, or password was incorrect
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026