nginx cannot read the Let's Encrypt private key: permission denied
error:0200100D:system library:fopen:Permission deniedShort answer
Certbot creates the live and archive folders under /etc/letsencrypt so only root can read them. If nginx, or the user your setup runs it as, is not root, opening privkey.pem fails with a permission error. Check the path with namei, then give the nginx group read access to the folders and the key.
Fix it fast
1Find out which cause you have
Show the permissions on every part of the path, and the user nginx runs as.
sudo namei -l /etc/letsencrypt/live/example.com/privkey.pem ps -o user= -C nginx | sort -u2Match what you see, then jump to its fix
What does the error look like?
error:0200100D:system library:fopen:Permission deniednginx fails to start or reload and names /etc/letsencrypt/live/example.com/privkey.pem
Cause 1 of 2
The live and archive folders are mode 0700
1Check
The Certbot guide says the containing directories are created with 0700, so only root can read them.
sudo ls -ld /etc/letsencrypt/live /etc/letsencrypt/archive2Fix
The guide gives chmod 0755 on live and archive, for installs that will never downgrade Certbot. Keys stay protected by their own file mode.
sudo chmod 0755 /etc/letsencrypt/live /etc/letsencrypt/archive3Verify
Test the nginx config as the service would load it, then reload.
sudo nginx -t && sudo systemctl reload nginxConfirmed by eff-certbot.readthedocs.io
Cause 2 of 2
privkey.pem is not readable by the user that opens it
1Check
For a server that drops root privileges, the Certbot guide says to change the group of privkey.pem and set it to 0640. privkey.pem must be kept secret at all times.
sudo ls -lL /etc/letsencrypt/live/example.com/privkey.pem2Fix
Give a group that the server user belongs to read access to the key, and keep it closed to everyone else.
sudo chgrp ssl-cert /etc/letsencrypt/archive/example.com/privkey*.pem
sudo chmod 0640 /etc/letsencrypt/archive/example.com/privkey*.pem3Verify
Reload nginx.
sudo nginx -t && sudo systemctl reload nginxConfirmed by eff-certbot.readthedocs.io
How do I stop it coming back?
- Keep the key group and mode in a Certbot renewal hook, so a renewal does not undo them.
- Use a Certbot deploy hook to reload nginx after renewal.
- Never make privkey.pem world-readable.
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
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 fixServers
Gunicorn rejects a request with "Error parsing headers: limit request headers fields size"
Error parsing headers: 'limit request headers fields'
Gunicorn caps the size of one header field at 8190 bytes and the number of headers at 100 by default.
2 causes, each with a fixServers
HAProxy answers 503 "No server is available to handle this request"
No server is available to handle this request.
HAProxy sends 503 when it has no server to give a request to.
4 causes, each with a fix