Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
echo | openssl s_client -connect shop.example.com:443 -servername shop.example.com 2>/dev/null | openssl x509 -noout -subject -issuer -enddate
subject=CN=shop.example.com
issuer=C=US, O=Let's Encrypt, CN=R12
notAfter=Feb 10 08:14:22 2027 GMT
openssl x509 -in /etc/ssl/certs/shop.crt -noout -enddate
certbot certificatesStep by step
- A live site — always add
-servername(SNI), or you may get the wrong (default) certificate:
echo | openssl s_client -connect shop.example.com:443 -servername shop.example.com 2>/dev/null | openssl x509 -noout -dates -ext subjectAltName-ext subjectAltName shows all names the certificate is valid for.
- Will it expire soon?
-checkendgives an exit code — perfect for scripts and monitoring (2592000 seconds = 30 days):
openssl x509 -in shop.crt -noout -checkend 2592000 && echo "OK for 30+ days" || echo "EXPIRES within 30 days"- Other ports and protocols (mail, databases):
echo | openssl s_client -connect mail.example.com:465 2>/dev/null | openssl x509 -noout -enddate
echo | openssl s_client -connect mail.example.com:25 -starttls smtp 2>/dev/null | openssl x509 -noout -enddate- The whole chain — a missing intermediate certificate breaks some clients even when the server certificate is fine:
echo | openssl s_client -connect shop.example.com:443 -servername shop.example.com -showcerts 2>/dev/null | grep -E ' s:| i:'
echo | openssl s_client -connect shop.example.com:443 -servername shop.example.com 2>/dev/null | grep 'Verify return code'
Verify return code: 0 (ok)- Many hosts at once — a small script for a daily report:
#!/bin/bash
for h in shop.example.com api.example.com mail.example.com; do
end=$(echo | openssl s_client -connect "$h:443" -servername "$h" 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
days=$(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 ))
echo "$days days $h ($end)"
done | sort -n- Kubernetes with cert-manager:
Check that it worked
After a renewal, check the live site again (not only the file): the notAfter date is new. If the file is new but the site shows the old date, the web server was not reloaded (systemctl reload nginx).
Common problems
| Problem | Cause | Fix |
|---|---|---|
| You see the wrong certificate | No -servername (SNI) — you got the default site's certificate. | Always add -servername HOST. |
| File renewed, site still shows the old date | The web server keeps the old certificate in memory. | Reload it; add a deploy hook to certbot. |
Verify return code: 20 (unable to get local issuer certificate) | The server does not send the intermediate certificate. | Use the full chain file (fullchain.pem), not only cert.pem. |
Verify return code: 10 (certificate has expired) | Expired. | Renew now (certbot renew --force-renewal for one cert with --cert-name), then reload. |
| The script hangs | s_client waits for input. | Start it with echo | or </dev/null. |
date: invalid date in the script | Not GNU date (macOS). | Run it on Linux, or use -checkend. |
Go further
- Command pages: openssl, certbot, curl, kubectl.
- Next how-tos: Get a free TLS certificate with Let's Encrypt, Test if a remote port is open, Check the TLS settings of a website, Create a self-signed certificate, Monitor TLS certificates with Prometheus.
- Full guides: Certbot, cert-manager. Alerts: Uptime Kuma, Prometheus.
- At work: openssl in daily use, certbot in daily use.
- Practise: Lab: applied cryptography with OpenSSL.
1Why must you add -servername to openssl s_client?
Many sites share one IP; without SNI the server may send the certificate of another (default) site.
2Which openssl option tells a script "this certificate expires within 30 days"?
openssl x509 -checkend 2592000 (exit code 1 if it expires in that time).