nginx cannot start: 'problems getting password' for the SSL key
SSL_CTX_use_PrivateKey_file("/etc/nginx/ssl/example.com.key") failedShort answer
nginx found the private key but could not decrypt it. The key file is protected by a passphrase and nginx has none to try, or the one it has is wrong. Give nginx the passphrase through ssl_password_file, or store the key without a passphrase. Then test the config and reload.
Fix it fast
1Find out which cause you have
Look at the first line of the key file. A key whose header mentions encryption needs a passphrase to be read.
head -n 3 /etc/nginx/ssl/example.com.key2Match what you see, then jump to its fix
- 1
The key file's header mentions encryption, and the nginx config has no ssl_password_file line.The key is passphrase-protected and nginx is given no passphraseFix - 2
ssl_password_file is set and the same error remains.The password file holds the wrong passphraseFix - 3
You cannot or do not want to keep a passphrase file next to the key.You would rather keep a key with no passphrase on the serverFix
- 1
What does the error look like?
SSL_CTX_use_PrivateKey_file("/etc/nginx/ssl/example.com.key") failedproblems getting password
Cause 1 of 3
The key is passphrase-protected and nginx is given no passphrase
1Check
Search the config for the directive and for the key path that is loaded.
grep -R -n -E "ssl_password_file|ssl_certificate_key" /etc/nginx/2Fix
Write the passphrase on one line in a file only root can read, and name that file with ssl_password_file. nginx tries each line in turn when it loads a key.
echo 'the-passphrase' | sudo tee /etc/nginx/ssl/example.com.pass > /dev/null
sudo chmod 600 /etc/nginx/ssl/example.com.pass
# in the server or http block
ssl_password_file /etc/nginx/ssl/example.com.pass;
ssl_certificate_key /etc/nginx/ssl/example.com.key;3Verify
Test the configuration, then reload.
sudo nginx -t && sudo systemctl reload nginxConfirmed by nginx.org
Cause 2 of 3
The password file holds the wrong passphrase
1Check
Prove the passphrase on the key itself, outside nginx. openssl pkey reads the key and takes the password from the source you name with -passin.
openssl pkey -in /etc/nginx/ssl/example.com.key -passin file:/etc/nginx/ssl/example.com.pass -noout2Fix
If the command fails, the passphrase is wrong: put the right one in the file, one passphrase per line when several keys are used. If it succeeds, check the file path in the nginx config for a typo.
sudo nano /etc/nginx/ssl/example.com.pass3Verify
The openssl command prints nothing and exits cleanly, then nginx accepts the config.
openssl pkey -in /etc/nginx/ssl/example.com.key -passin file:/etc/nginx/ssl/example.com.pass -noout && echo key-ok
sudo nginx -tConfirmed by docs.openssl.org
Cause 3 of 3
You would rather keep a key with no passphrase on the server
1Check
A key written by openssl pkey is unencrypted unless a cipher option is given, so a copy made this way needs no passphrase.
openssl pkey -in /etc/nginx/ssl/example.com.key -passin file:/etc/nginx/ssl/example.com.pass -out /etc/nginx/ssl/example.com.plain.key2Fix
Point ssl_certificate_key at the plain copy, lock the file down, and delete the passphrase file if nothing else uses it.
sudo chmod 600 /etc/nginx/ssl/example.com.plain.key
ssl_certificate_key /etc/nginx/ssl/example.com.plain.key;3Verify
Test the configuration and reload nginx.
sudo nginx -t && sudo systemctl reload nginxConfirmed by docs.openssl.org
How do I stop it coming back?
- Decide once whether the server key is stored with a passphrase, and note the choice next to the config.
- Keep the passphrase file and the key out of version control, with mode 600.
- Run nginx -t after every key or certificate change, before the reload.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
nginx refuses to start: private key does not match the certificate
SSL: error:05800074:x509 certificate routines::key values mismatch
nginx pairs the private key with the first certificate in the ssl_certificate file.
2 causes, each with a fixServers
nginx will not start because the SSL certificate file is missing
nginx: [emerg] cannot load certificate key "/etc/nginx/ssl/example.com.key": ... No such file or directory
nginx opens every certificate and key file named in the config while it starts, and one of them is not there.
3 causes, each with a fixServers
A Let's Encrypt certificate did not renew with Certbot
Type: connection ... Timeout during connect (likely firewall problem)
Run sudo certbot renew --dry-run and read the Type and Detail lines.
6 causes, each with a fixServers
curl cannot connect to port 80 or 443 on a server running nginx
CURLE_COULDNT_CONNECT (7): Failed to connect() to host or proxy
Exit code 7 means the TCP connection itself failed, before any HTTP happened.
3 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fixServers
Your website on a Google Compute Engine VM times out on port 80
The site works with curl on the VM but not from outside
A timeout, as opposed to a refusal, usually means a firewall dropped the packets.
3 causes, each with a fix