All posts

How to check SSL certificate expiry for every domain on a cPanel server

AutoSSL renews most certificates on a cPanel & WHM server without anyone touching them. That's exactly why an expired one is a surprise: the customer sees the browser warning before you do, and the fix starts with working out why a process that normally just works didn't.

This guide covers the manual checks, all read-only unless marked otherwise:

  1. where cPanel keeps the certificates it serves,
  2. one domain's expiry, then every domain's,
  3. only the ones expiring soon,
  4. what a site is actually serving to visitors,
  5. why AutoSSL skipped a domain.

Where cPanel keeps the certificates

Apache on a cPanel server reads each domain's certificate from cPanel's own store. The file Apache uses for a virtual host is:

/var/cpanel/ssl/apache_tls/<domain>/combined

combined holds the private key, the certificate and the CA chain in one file. That's fine for reading: openssl x509 skips the key and reads the first certificate it finds, which is the domain's own.

The directory name is the virtual host's main domain. Subdomains, www. and aliases on the same virtual host are usually names on that one certificate rather than separate directories.

Treat these files as read-only. They contain private keys, so don't copy them around or paste them into tickets.

Check one domain

openssl x509 -noout -subject -issuer -enddate \
  -in /var/cpanel/ssl/apache_tls/example.com/combined

You get three lines: who the certificate is for, who issued it, and notAfter, the expiry date. To see every name it covers:

openssl x509 -noout -ext subjectAltName \
  -in /var/cpanel/ssl/apache_tls/example.com/combined

If a customer says "the site works but the shop subdomain shows a warning", this is the first thing to run: the subdomain may not be on the certificate at all.

Every domain, soonest first

Loop over the store and print each expiry as a sortable date:

for f in /var/cpanel/ssl/apache_tls/*/combined; do
  d=$(basename "$(dirname "$f")")
  end=$(openssl x509 -enddate -noout -in "$f" | cut -d= -f2)
  printf '%s\t%s\n' "$(date -d "$end" +%F)" "$d"
done | sort

The top of the list is what needs attention. On a healthy server running AutoSSL, nothing should be close: AutoSSL renews well before the end date, so a certificate in its last couple of weeks means renewal has been failing for a while.

Only the ones expiring soon

openssl x509 -checkend <seconds> exits with status 1 when the certificate expires within that many seconds. 30 days is 2592000:

for f in /var/cpanel/ssl/apache_tls/*/combined; do
  openssl x509 -checkend 2592000 -noout -in "$f" >/dev/null || \
  echo "$(basename "$(dirname "$f")")  $(openssl x509 -enddate -noout -in "$f" | cut -d= -f2)"
done

It prints nothing when everything is fine, which makes it easy to run from cron. Save it as a script in root's home directory and schedule it weekly; cron mails any output to the crontab's MAILTO address, so you only hear about it when something is inside the window.

Already-expired certificates show up here too, because they "expire within 30 days" as well.

Check what the site is really serving

The file on disk and the certificate a visitor gets aren't always the same thing. A domain can point at a CDN or proxy, at another server, or at a load balancer with its own certificate. Ask the site directly:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -enddate

-servername sends SNI. On a server with many sites on one IP address, leave it out and you'll likely get the server's default certificate instead of the site's.

Compare the result with the file from the previous step:

  • Same expiry, same issuer: the visitor gets the certificate on this server.
  • Different issuer (a CDN's, for example): the visitor never sees your certificate. The expiry that matters is the CDN's, and the one on your server only matters between the CDN and you.
  • Connection refused or a different server's certificate: check where the domain points: dig +short A example.com @1.1.1.1.

The same check works for the server's own services. Use the hostname and the service's port, such as 2083 for cPanel, 2087 for WHM, 993 for IMAP and 465 for SMTP. Those certificates are managed in WHM » Service Configuration » Manage Service SSL Certificates, not through the domain store above.

Why AutoSSL didn't renew a domain

Start with AutoSSL's own record. In WHM, open SSL/TLS » Manage AutoSSL and the Logs tab: each run lists the domains it checked and the reason any of them failed domain control validation (DCV). The log files live under /var/cpanel/logs/autossl/ if you'd rather read them on the command line.

The reasons fall into a few groups, each with a read-only check.

1. The domain points somewhere else. DCV has to reach this server. Ask a public resolver, not the server's own DNS (which answers for every zone it hosts, even after the domain has moved):

dig +short A example.com @1.1.1.1
dig +short AAAA example.com @1.1.1.1

If the A record is another host, the domain has probably moved and the customer never removed it from the account. Don't remove it yourself; ask them. An AAAA record pointing to an address this server doesn't serve can break validation even when the A record is right.

2. A CAA record that doesn't allow the issuer. CAA records list which certificate authorities may issue for a domain:

dig +short CAA example.com @1.1.1.1

No output means no restriction. If there are records and none of them names the CA your AutoSSL provider uses (WHM shows the provider on the Manage AutoSSL page), issuance is refused. The fix is a CAA record at the customer's DNS provider.

3. Something blocks /.well-known/. HTTP validation fetches a file from the site's /.well-known/ path. A redirect to another host, a deny rule or a security plugin can stop it:

curl -sI http://example.com/.well-known/pki-validation/ | head -5

A redirect to the same site's HTTPS address is usually fine. A redirect to a different domain or a 403 points at the account's .htaccess or an application rule.

Re-running the check (not read-only). Once you've fixed the cause, you can run AutoSSL for one account instead of waiting for the next scheduled run:

/usr/local/cpanel/bin/autossl_check --user=USERNAME

This is a real AutoSSL run: it can request, install and replace certificates for that user's domains. Run it for the account you fixed, not for every account at once.

A short year-end routine

  1. Run the 30-day loop. Anything it prints gets a look this week.
  2. For each domain on the list, compare the file with s_client, then read the AutoSSL log for that domain.
  3. Fix DNS, CAA or .well-known problems with the customer, then re-run autossl_check for that one account.
  4. Put the 30-day loop in cron so next year's surprise reaches you, not the customer.

Doing this from WHM

If you'd rather not keep the loop in cron, Server Commander, our plugin for cPanel & WHM, has an SSL Audit tool that goes through every account's domains and lists each certificate's expiry date, days left and issuer, soonest first, inside WHM. It's one of the tools in Server Commander, alongside the Large File Finder and WP Core Audit. Server Commander is $19.99/month per server, or part of the Server+ Full Suite.

The commands above work on any cPanel server either way.

cPanel® and WHM® are trademarks of cPanel, L.L.C. Server+ is an independent product and is not affiliated with or endorsed by cPanel.