Skip to content
The Chat Archive
gpt-4.1-mini-2025-04-14· OpenAI WildChat-4.8M (AI2)

how to check if ssl is expired in ubuntu

  1. User

    how to check if ssl is expired in ubuntu

  2. 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 openssl

    You 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 -dates
    

    Explanation:

    • -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 GMT
    

    You can check the notAfter date 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. .crt or .pem), use:

    openssl x509 -in /path/to/certificate.crt -noout -dates
    

    Output 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-check
    

    Then check:

    ssl-cert-check -s example.com
    

    This will show expiry date and days until expiration.


    4. Using curl

    You can also get the expiry date using curl with verbose:

    curl -vI https://example.com 2>&1 | grep expire
    

    But this is less reliable than openssl for 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!

  3. User

    my website is rma.rptechindia.com

  4. Assistant

    To check if the SSL certificate for your website rma.rptechindia.com is 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 -dates
    

    Example output:

    notBefore=Apr 15 00:00:00 2024 GMT
    notAfter=Jul 14 23:59:59 2024 GMT
    
    • notAfter shows 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!