how to check if ssl is expired in ubuntu
- User
how to check if ssl is expired in ubuntu
- Assistant
To check if an SSL certificate is expired on Ubuntu, you can use several methods depending on where the certificate is located (a remote server or a local file). Here are common approaches:
1. Check SSL Expiry on a Remote Server Using
opensslYou can connect to the server's SSL port (usually 443) and retrieve certificate details, including the expiry date:
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -datesExplanation:
-servername example.com– for SNI (Server Name Indication)-connect example.com:443– connect to the server and port- The output will be:
notBefore=May 10 00:00:00 2023 GMT notAfter=Aug 8 23:59:59 2023 GMTYou can check the
notAfterdate to see if it's in the future or expired.
2. Check SSL Expiry of a Local Certificate File
If you have the certificate file (e.g.
.crtor.pem), use:openssl x509 -in /path/to/certificate.crt -noout -datesOutput example:
notBefore=Jun 10 12:00:00 2023 GMT notAfter=Sep 10 12:00:00 2023 GMT
3. Using
ssl-cert-check(install first)You can install a tool to check SSL expiration:
sudo apt update sudo apt install ssl-cert-checkThen check:
ssl-cert-check -s example.comThis will show expiry date and days until expiration.
4. Using
curlYou can also get the expiry date using
curlwith verbose:curl -vI https://example.com 2>&1 | grep expireBut this is less reliable than
opensslfor cert expiration.
5. Automated Scripting Example
Here’s a quick way to check if a certificate is expired:
expiry_date=$(echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2) expiry_seconds=$(date --date="$expiry_date" +%s) now_seconds=$(date +%s) if [ $expiry_seconds -lt $now_seconds ]; then echo "Certificate is expired." else echo "Certificate is valid." fi
Let me know if you want help with a specific scenario!
- User
my website is rma.rptechindia.com
- Assistant
To check if the SSL certificate for your website
rma.rptechindia.comis expired or when it will expire, you can run the following command on your Ubuntu machine:echo | openssl s_client -servername rma.rptechindia.com -connect rma.rptechindia.com:443 2>/dev/null | openssl x509 -noout -datesExample output:
notBefore=Apr 15 00:00:00 2024 GMT notAfter=Jul 14 23:59:59 2024 GMTnotAftershows the expiry date of the certificate. If that date is in the past (compared to today’s date), your certificate has expired.
Alternative: Check expiry in a human-friendly way using a one-liner
expiry_date=$(echo | openssl s_client -servername rma.rptechindia.com -connect rma.rptechindia.com:443 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2) echo "Certificate expires on: $expiry_date"This will print the expiry date directly.
Optional: Check days left until expiry
Run this script to see days remaining:
expiry_date=$(echo | openssl s_client -servername rma.rptechindia.com -connect rma.rptechindia.com:443 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2) expiry_seconds=$(date --date="$expiry_date" +%s) now_seconds=$(date +%s) days_left=$(( ($expiry_seconds - $now_seconds) / 86400 )) if [ $days_left -lt 0 ]; then echo "Certificate has expired." else echo "Certificate is valid for $days_left days." fi
Let me know if you want me to check it for you or help with renewing or installing the certificate!