Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

nginx cannot start: 'problems getting password' for the SSL key

ErrorSSL_CTX_use_PrivateKey_file("/etc/nginx/ssl/example.com.key") failed

Short 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.

  • Applies to nginx 1.26, OpenSSL 3.0, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.key
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2ssl_password_file is set and the same error remains.The password file holds the wrong passphraseFix
    3. 3You 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

What does the error look like?

  • SSL_CTX_use_PrivateKey_file("/etc/nginx/ssl/example.com.key") failed
  • problems 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 nginx

Confirmed by nginx.org

Did this fix it?

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 -noout

2Fix

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.pass

3Verify

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 -t

Confirmed by docs.openssl.org

Did this fix it?

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.key

2Fix

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 nginx

Confirmed by docs.openssl.org

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.