TLS certificates explained

A TLS certificate binds your domain name to a public key and is signed by a certificate authority that browsers already trust, through one or more intermediate certificates that your server must send along. On a VPS you usually get free certificates from Let's Encrypt with certbot, serve the fullchain file plus the private key, and let a timer renew them automatically.

Networking and security guide, updated 2026-12-03

What is inside a certificate?

A certificate is a signed statement: "this public key belongs to www.example.com". The main fields:

  • Subject Alternative Names (SAN): the list of names the certificate covers, such as example.com and www.example.com. Browsers check this list, not the older Common Name field.
  • Validity: a not-before and not-after date.
  • Public key: the half of your key pair that clients use during the handshake.
  • Issuer and signature: who vouches for it.

Read any certificate file with:

openssl x509 -in cert.pem -noout -subject -issuer -dates -ext subjectAltName

The private key never appears in the certificate. It stays on your server, readable by root only. Anyone who gets the key can impersonate your site until the certificate expires, so treat it like a password.

How do chains and intermediates work?

Browsers and operating systems ship a small set of trusted root certificates. Roots are kept offline, so they sign intermediate certificates, and intermediates sign the leaf certificate for your domain. The client must build a path from your leaf up to a root it trusts.

Clients have the roots, but not necessarily the intermediates. Your server must therefore send the leaf and the intermediate in the handshake. That combination is the chain. Leave out the intermediate and some clients still work, because they cached it from another site or fetch it themselves, while others fail with a trust error. The result is the worst kind of bug: it works on your laptop and breaks on a phone or in curl.

The order matters too: leaf first, then the intermediate that signed it. The root itself is not needed and only adds bytes.

Which key type should you use?

Two key types are in common use:

  • ECDSA (P-256 or P-384): small keys, fast handshakes, supported by every current browser and client library. Certbot has used ECDSA by default since version 2.0, and Ubuntu 24.04 and Debian 13 ship newer versions.
  • RSA (2048 or 3072 bits): larger and slower to sign, but accepted by very old clients such as outdated embedded devices.

ECDSA is the right default. If you must serve ancient clients, you can hold both an ECDSA and an RSA certificate for the same name; HAProxy and Nginx can serve whichever the client supports. Force a type in certbot with --key-type rsa or --key-type ecdsa. On a busy balancer, ECDSA also saves CPU, since handshakes are the main TLS cost.

How does Let's Encrypt verify your domain?

Let's Encrypt issues certificates automatically after you prove control of the name through a challenge:

ChallengeWhat you proveNeedsWildcards
HTTP-01You serve a token at /.well-known/acme-challenge/Port 80 reachable, DNS pointing at the serverNo
DNS-01You publish a TXT record at _acme-challenge.example.comAccess to change DNS, ideally by APIYes

HTTP-01 is the easy path for a single server: the DNS record already points there and port 80 is open. It fails when port 80 is closed in the firewall, when DNS still points at an old server, or when an AAAA record points at an IPv6 address where nothing answers, because the validator prefers IPv6 when it exists.

DNS-01 works for servers that are not yet public, for internal names and for wildcards. Certbot has DNS plugins for many providers (packages named python3-certbot-dns-...); otherwise --manual --preferred-challenges dns asks you to add the TXT record by hand, which cannot renew automatically.

How do you get and renew a certificate with certbot?

On Ubuntu 24.04 or Debian 13 with Nginx:

apt install -y certbot python3-certbot-nginx
certbot --nginx -d example.com -d www.example.com

Without a web server plugin, use certbot certonly --webroot -w /var/www/html -d example.com or --standalone when port 80 is free. On Rocky and Alma, install certbot from EPEL: dnf install -y epel-release && dnf install -y certbot.

The apt package installs a certbot.timer that runs twice a day and renews any certificate close to expiry. Confirm and test it:

systemctl list-timers certbot.timer
certbot renew --dry-run
certbot certificates

Let's Encrypt certificates are short lived (90 days today, with shorter lifetimes announced for the coming years) and Let's Encrypt no longer sends expiry reminder emails, so automation plus your own monitoring is the only safe setup. Software that reads the files once at start, such as HAProxy, needs a deploy hook in /etc/letsencrypt/renewal-hooks/deploy/ that reloads it. Full Nginx setup is in Nginx with HTTPS.

What is the difference between cert.pem, chain.pem and fullchain.pem?

Certbot keeps the current files under /etc/letsencrypt/live/example.com/ as links to numbered versions in archive/:

  • cert.pem: the leaf certificate alone.
  • chain.pem: the intermediate certificate(s).
  • fullchain.pem: leaf plus intermediates, in the right order.
  • privkey.pem: the private key.

Nearly every modern server wants fullchain.pem plus privkey.pem. In Nginx that is ssl_certificate and ssl_certificate_key. Configuring cert.pem where fullchain.pem belongs is the most common cause of an incomplete chain. HAProxy wants fullchain and key concatenated into one file, as in the HAProxy guide. Always point configs at the live/ paths, never at archive/, so renewals take effect.

How do you check a live certificate with openssl?

From any machine:

openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null

Look for three things in the output. The Certificate chain section should list at least two certificates (your leaf at depth 0 and an intermediate at depth 1). The end of the output should say Verify return code: 0 (ok). And the leaf subject must match the name you asked for. -servername matters: without it the server may hand back its default certificate.

Shortcuts for daily use:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -ext subjectAltName
curl -vI https://example.com 2>&1 | grep -E "expire|subject|issuer"

Put the first line into a cron job or your monitoring and alert when fewer than 14 days remain.

What are the usual errors and how do you fix them?

  • Incomplete chain. openssl prints unable to verify the first certificate or unable to get local issuer certificate; curl and some phones refuse, desktop browsers may work. Fix: serve fullchain.pem, reload the server.
  • Name mismatch. Browsers show a common name error, curl says no alternative certificate subject name matches target host name. The SAN list lacks the name you used, often the bare domain or www. Fix: reissue with every name as a -d option, or check that the right server block answers that name.
  • Expired. The not-after date has passed. Usually renewal ran but the server never reloaded, or the timer failed. Run certbot renew, read /var/log/letsencrypt/letsencrypt.log, and add a reload hook.
  • Validation failed on renewal. Port 80 was closed in the firewall later, or DNS moved. Open port 80 or switch to DNS-01.
  • Too many certificates. Let's Encrypt has rate limits per domain and for identical certificates per week. Test with --dry-run or --test-cert, which use the staging service.

When should you use HSTS and wildcard certificates?

HSTS is a response header, Strict-Transport-Security: max-age=31536000; includeSubDomains, telling browsers to use HTTPS only for that domain for the given time. It protects against downgrade attacks, but it is hard to undo: a browser that saw it refuses plain HTTP until it expires, even if your certificate breaks. Start with a short max-age such as 300, raise it once renewals have run smoothly, add includeSubDomains only when every subdomain has HTTPS, and treat preload as permanent.

A wildcard certificate for *.example.com covers one level of subdomains (a.example.com, not x.a.example.com) and not the bare example.com, so request both names. It needs DNS-01. Wildcards are handy for many short-lived subdomains, but a stolen wildcard key exposes every subdomain, so on a small setup separate certificates per name are often the cleaner choice.

Questions about this guide

Do CheapVPS servers come with a certificate?

No certificate is preinstalled, since it must match your domain. Point the domain at the server as in Point a domain at your server, then run certbot; the whole process takes a few minutes.

Can I get a certificate for the bare IP address?

Most servers use a domain name. Certificates for IP addresses exist but are uncommon and short lived. For admin access, an SSH tunnel or a WireGuard link is usually simpler.

Why does my site work in the browser but fail in curl?

Almost always an incomplete chain: the browser filled in the missing intermediate, curl did not. Serve fullchain.pem and reload.

Does the certificate need port 443 open?

Serving HTTPS needs 443. Issuing with HTTP-01 needs port 80 open as well, during issuance and every renewal. DNS-01 needs neither.

Can I copy a certificate to a second server?

Yes, copy fullchain.pem and privkey.pem securely, for example with rsync over SSH. You then have to repeat the copy after every renewal, so it is usually easier to request a certificate on each server or terminate TLS on one load balancer.

What happens when I rebuild the server?

A rebuild wipes the disk, including /etc/letsencrypt. Request a new certificate after setup, or restore the directory from your own backup if you want the same account and files.