Sub topic 9
Understanding the Certificate Files Certbot Creates
This chapter assumes you can use a Linux shell with sudo and that you have already obtained a certificate with Certbot, as in the previous chapter. You should also know what a certificate and a private key are. Here you will learn what Certbot writes to disk, how the files relate to each other, and which ones your web server should read.
Why the layout matters
After a successful run, Certbot leaves many files under /etc/letsencrypt. If you point nginx at the wrong one, you can get a site that works in a browser but fails in other clients, or a site that silently keeps serving an expired certificate after renewal. Knowing which path is stable and which is not prevents both problems.
The directory tree
Certbot keeps all of its state in /etc/letsencrypt. The main subdirectories are:
| Path | Purpose |
|---|---|
| `live/` | One directory per certificate name. Contains symlinks to the current files. |
| `archive/` | The real files, with a number added to each name. Every renewal adds a new set. |
| `renewal/` | One `.conf` file per certificate. It records how to renew that certificate. |
| `accounts/` | Your ACME account key and registration data for each CA server. |
| `renewal-hooks/` | Scripts that run before, after, or on deploy of a renewal. |
| `keys/` and `csr/` | Older copies of keys and certificate signing requests, kept by some versions. |
Only live/ is meant for your web server configuration. The other directories are Certbot's own bookkeeping.
The four files in live/
List the directory for your certificate:
sudo ls -l /etc/letsencrypt/live/example.com/
sudo certbot certificatesYou will see output similar to this:
cert.pem -> ../../archive/example.com/cert1.pem
chain.pem -> ../../archive/example.com/chain1.pem
fullchain.pem -> ../../archive/example.com/fullchain1.pem
privkey.pem -> ../../archive/example.com/privkey1.pem
READMEEach entry is a symlink (a file that points to another file). The number in the target name is the renewal counter. After the first renewal the links point to cert2.pem, privkey2.pem, and so on.
cert.pem
This is the leaf certificate, also called the end-entity certificate. It holds the public key, the domain names (in the Subject Alternative Name field), the validity dates, and the signature from the issuing CA. It contains only your certificate, with no intermediates.
chain.pem
This holds the intermediate certificate or certificates that link your leaf to a root the client already trusts. It does not include the root. Clients ship with root certificates in their trust store, so the server does not need to send it.
fullchain.pem
This is cert.pem followed by chain.pem in one file. A TLS server should send the leaf and the intermediates together during the handshake. If it sends only the leaf, some clients cannot build a path to a trusted root and report an error. Browsers can sometimes recover by fetching the missing intermediate, but tools such as curl, Java clients, and many API libraries cannot.
privkey.pem
This is the private key that matches the public key in the certificate. Whoever holds it can impersonate your server. It must never leave the machine unless you have a deliberate reason.
Which file goes where
For nginx, use two of the four files:
| nginx directive | File |
|---|---|
| `ssl_certificate` | `fullchain.pem` |
| `ssl_certificate_key` | `privkey.pem` |
Using cert.pem for ssl_certificate is the most common mistake. The site may load in a desktop browser and still fail for other clients. Some other software, such as certain mail servers, asks for the pieces separately. In that case cert.pem and chain.pem are the right inputs.
Why symlinks and numbered archives
When Certbot renews a certificate, it writes a new set of numbered files into archive/. Then it moves the live/ symlinks to the new files. Your nginx configuration never changes, because it names the live/ paths.
This design has three useful effects:
- The switch happens as a repoint of links, so there is no moment when a path holds a half-written file.
- Old versions stay in
archive/, so you can inspect or roll back to a previous certificate. - Your configuration stays valid across renewals.
Nginx reads the files only when it starts or reloads. The new files are therefore not served until you reload nginx. The chapter on renewal hooks covers how to automate that step.
Do not edit or copy from live/ carelessly
Never delete or rename files in live/ by hand. Certbot expects to manage the links. If you copy privkey.pem to another location, that copy does not follow renewals and will become stale. If a different program needs the files, point it at the live/ path, or use a deploy hook that copies fresh files after each renewal.
Inspecting a certificate file
You can read the contents of a PEM file with openssl. PEM is a text format, where the binary data is Base64-encoded between -----BEGIN and -----END lines.
sudo openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem \
-noout -subject -issuer -dates -ext subjectAltNameThis prints the subject, the issuer, the start and end dates, and every domain the certificate covers. To count how many certificates fullchain.pem contains:
sudo grep -c 'BEGIN CERTIFICATE' /etc/letsencrypt/live/example.com/fullchain.pemA typical result is 2: your leaf plus one intermediate. The exact number can change when Let's Encrypt changes its chain, so do not hard-code it in scripts.
To confirm that a key and certificate belong together, compare their public keys:
sudo openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem -noout -pubkey | sha256sum
sudo openssl pkey -in /etc/letsencrypt/live/example.com/privkey.pem -pubout | sha256sumIf the two hashes match, the key and certificate are a pair. A mismatch is a frequent cause of nginx refusing to start with a "key values mismatch" error.
The renewal configuration file
Each certificate has a file such as /etc/letsencrypt/renewal/example.com.conf. View it:
sudo cat /etc/letsencrypt/renewal/example.com.confIt records the pieces of your original request: the paths in live/ and archive/, the authenticator (for example nginx), the account, and the challenge type. When certbot renew runs, it reads this file to repeat the same request. If you change how you want to authenticate, for example from webroot to nginx, change it by running Certbot again with the new options or by editing this file carefully, and then test with a dry run.
The server line in this file shows which CA the certificate came from. A certificate obtained with --staging will name the staging server. That certificate is not trusted by browsers, so check this line if a new certificate triggers browser warnings.
File permissions and key protection
Check the permissions:
sudo ls -ld /etc/letsencrypt/live /etc/letsencrypt/archive
sudo ls -l /etc/letsencrypt/archive/example.com/Certbot makes the live/ and archive/ directories readable only by root, and the private key files mode 0600. Certificates are public by nature, so their files may be more open, but the key must stay restricted.
Nginx starts as root, reads the files, and then drops privileges to its worker user. That is why nginx needs no special permissions on the key. Services that start as an unprivileged user, such as some Java or Node.js applications, do need a controlled way to read it.
Common problems
- nginx: cannot load certificate. The path is wrong, or Certbot used a different name for the directory, such as
example.com-0001. Runsudo certbot certificatesto see the real path. - Browser shows an old expiry date after renewal. The files updated, but nginx was not reloaded.
- Some clients report an incomplete chain.
ssl_certificatepoints tocert.peminstead offullchain.pem. - Key values mismatch. The certificate and key come from different renewals or different certificates. Compare the public key hashes as shown above.
Exercise
Your nginx site loads correctly in Chrome, but curl reports "unable to get local issuer certificate". Which file is most likely set in ssl_certificate, which file should it be, and why does the browser still work?
Show answer
It is most likely cert.pem. It should be fullchain.pem, which adds the intermediate certificates after the leaf. Chrome can often fetch a missing intermediate on its own, but curl cannot, so it cannot build a path from your leaf to a trusted root.
Exercise
After a renewal, ls -l /etc/letsencrypt/live/example.com/ shows links to privkey2.pem, but visitors still see the old certificate. What explains this, and what command fixes it safely?
Show answer
Nginx reads the certificate files only at start or reload, so it still holds the old certificate in memory. Run sudo nginx -t && sudo systemctl reload nginx. The test checks the configuration first, and the reload loads the new files without dropping connections.
Exercise
Why should you configure services to read from live/ and not from archive/?
Show answer
The names in archive/ carry a number that changes with every renewal, so a path such as privkey1.pem goes stale. The live/ symlinks always point to the current files, so the configuration stays valid after each renewal.