Skip to content
Log In Sign Up info@muvcloud.com

Check a Live Site

openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -dates

The output has two lines: notBefore, when the certificate became valid, and notAfter, when it expires. The -servername option sends the name the browser would send, so a server with several sites returns the right certificate. </dev/null closes the connection right after the handshake. More about the tool is in how to test SSL connections with openssl s_client.

This checks what the server presents now, which is the date that matters to visitors. A renewed certificate on disk does not help until the web server reloads.

Check a Certificate File

openssl x509 -in /etc/ssl/certs/example.com.crt -noout -enddate

For Let's Encrypt certificates the file is /etc/letsencrypt/live/example.com/cert.pem, readable with sudo. To see the names and the issuer as well:

sudo openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem -noout -subject -issuer -dates -ext subjectAltName

Ask Certbot

sudo certbot certificates

Certbot lists each certificate with its names, expiry date, and the number of days left. It reports what is on disk; compare it with the live check above.

Test for an Upcoming Expiry with -checkend

-checkend takes a number of seconds and answers whether the certificate will have expired by then. It prints a short message and, more usefully, sets the exit status: 0 when the certificate is still valid at that point, nonzero when it is not.

openssl x509 -in /etc/ssl/certs/example.com.crt -noout -checkend 1814400

1814400 seconds is 21 days. Use it in scripts and monitoring checks.

A Cron Check Script

Save this as /usr/local/bin/check-certs.sh. It works in Bash 5 and prints a line only for a problem. The basics of scripts are in how to write and run a Bash script.

#!/usr/bin/env bash
set -u

domains=(example.com www.example.com)
days=21
seconds=$((days * 86400))
status=0

for domain in "${domains[@]}"; do
    cert=$(timeout 15 openssl s_client -connect "${domain}:443" -servername "${domain}" </dev/null 2>/dev/null | openssl x509 2>/dev/null)
    if [ -z "${cert}" ]; then
        echo "${domain}: no certificate received"
        status=1
        continue
    fi
    if ! printf '%s\n' "${cert}" | openssl x509 -noout -checkend "${seconds}" >/dev/null; then
        end=$(printf '%s\n' "${cert}" | openssl x509 -noout -enddate)
        echo "${domain}: expires within ${days} days (${end#notAfter=})"
        status=1
    fi
done

exit "${status}"
sudo chmod 755 /usr/local/bin/check-certs.sh
/usr/local/bin/check-certs.sh; echo "exit status: $?"

Run it by hand once; with no problems it prints nothing and the exit status is 0.

Run the Check Every Day

Add a daily cron entry, for example in /etc/cron.d/check-certs:

30 7 * * * root /usr/local/bin/check-certs.sh | logger -t check-certs

This writes problems to the system log. Send them to whatever alerting you already use; the point is that someone sees them. To confirm the entry is in place, see how to list cron jobs.

Why a Check Is Worth Having

  • No reminders: Let's Encrypt stopped sending expiry e-mails on 4 June 2025.
  • Shorter lifetimes: Let's Encrypt certificates last 90 days today, with 64 days announced for its default profile from 10 February 2027 and 45 days from 16 February 2028.
  • All public certificates: the CA/Browser Forum's ballot SC-081 lowers the maximum to 100 days from 15 March 2027 and 47 days from 15 March 2029.

Renewal must be automatic and tested; this check catches the cases where it still fails. If renewal is the problem, start with how to renew Let's Encrypt certificates. If a certificate has already expired, visitors see NET::ERR_CERT_DATE_INVALID.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations