Maaz Zindani

Loading the index…

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

nginx cannot read the Let's Encrypt private key: permission denied

Errorerror:0200100D:system library:fopen:Permission denied

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

  • Applies to Certbot 4.x, nginx 1.26, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

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

    1. 1namei shows drwx------ root root on live or archiveThe live and archive folders are mode 0700Fix
    2. 2Folders are open, and the error names privkey.pemprivkey.pem is not readable by the user that opens itFix

What does the error look like?

  • error:0200100D:system library:fopen:Permission denied
  • nginx 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/archive

2Fix

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/archive

3Verify

Test the nginx config as the service would load it, then reload.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by eff-certbot.readthedocs.io

Did this fix it?

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

2Fix

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*.pem

3Verify

Reload nginx.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by eff-certbot.readthedocs.io

Did this fix it?

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

Next step

Want this handled for good?

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