In Chrome, clicking on the green HTTPS lock icon opens a window with the certificate details:

enter image description here

When I tried the same with cURL, I got only some of the information:

$ curl -vvI https://gnupg.org
* Rebuilt URL to: https://gnupg.org/
* Hostname was NOT found in DNS cache
*   Trying
* Connected to gnupg.org ( port 443 (#0)
* TLS 1.2 connection using TLS_DHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate: gnupg.org
* Server certificate: Gandi Standard SSL CA
* Server certificate: UTN-USERFirst-Hardware
> HEAD / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: gnupg.org
> Accept: */*

Any idea how to get the full certificate information form a command line tool (cURL or other)?


11 Answers 11


You should be able to use OpenSSL for your purpose:

echo | openssl s_client -showcerts -servername gnupg.org -connect gnupg.org:443 2>/dev/null | openssl x509 -inform pem -noout -text

That command connects to the desired website and pipes the certificate in PEM format on to another openssl command that reads and parses the details.

(Note that "redundant" -servername parameter is necessary to make openssl do a request with SNI support.)

  • 2
    @AdamMatan Did you include the full command after the second pipe? The error message looks like the second openssl invocation ended up running in interactive mode (ie openssl vs openssl x509 -inform pem -noout -text). What Pedro wrote works fine for me. – Håkan Lindqvist Jan 23 '15 at 22:45
  • 6
    Note that while s_client will print the whole chain, the last piped command will only print information about the first certificate. – chutz Jan 26 '16 at 17:06
  • 1
    echo by itself is equivalent to echo '' .. it sends an empty string to stdout. cat /dev/null | would work also and is a bit more self-explanatory. – hemp Jan 6 '18 at 1:06
  • 5
    If you would like to just know the expiry date, you can replace -text with -enddate, check for other options (openssl x509 help). – adriaan Jul 11 '18 at 10:12
  • 1
    (fixed) @hemp: echo by itself outputs one newline character, then exits which causes the pipe to return EOF to openssl, which is actually what causes openssl to complete. Redirecting with </dev/null (or Windows <NUL: but not on versions of OpenSSL before about 2016 which had a bug here) also works and is IMO even better. – dave_thompson_085 Sep 19 '18 at 20:32

Simple solution

That's my everyday script:

curl --insecure -vvI https://www.google.com 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }'


* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
*    server certificate verification SKIPPED
*    server certificate status verification SKIPPED
*    common name: www.google.com (matched)
*    server certificate expiration date OK
*    server certificate activation date OK
*    certificate public key: RSA
*    certificate version: #3
*    subject: C=US,ST=California,L=Mountain View,O=Google Inc,CN=www.google.com
*    start date: Wed, 24 May 2017 17:39:15 GMT
*    expire date: Wed, 16 Aug 2017 17:13:00 GMT
*    issuer: C=US,O=Google Inc,CN=Google Internet Authority G2
*    compression: NULL
* ALPN, server accepted to use http/1.1
* Connection #0 to host www.google.com left intact
  • 8
    Doesn't work for me, doesn't include the start/expire dates. – Per Lundberg Jun 1 '17 at 6:34
  • 8
    Since some recent change in curl (somewhere between 49 and 52) this doesn't display anything at all about the certificate. :( – Ross Presser Jun 26 '17 at 14:14
  • 1
    remove the 2>&1 – Jeshan Jun 11 '18 at 19:30
  • 2
    This also doesn't show Alternative Names which are on that cert. – Dimitry K Dec 17 '19 at 11:10
nmap -p 443 --script ssl-cert gnupg.org

The -p 443 specifies to scan port 443 only. All ports will be scanned if it is omitted, and the certificate details for any SSL service that is found will be displayed. The --script ssl-cert tells the Nmap scripting engine to run only the ssl-cert script. From the doc, this script "(r)etrieves a server's SSL certificate. The amount of information printed about the certificate depends on the verbosity level."

Sample output:

Starting Nmap 7.40 ( https://nmap.org ) at 2017-11-01 13:35 PDT
Nmap scan report for gnupg.org (
Host is up (0.16s latency).
Other addresses for gnupg.org (not scanned): (null)
rDNS record for www.gnupg.org
443/tcp open  https
| ssl-cert: Subject: commonName=gnupg.org
| Subject Alternative Name: DNS:gnupg.org, DNS:www.gnupg.org
| Issuer: commonName=Gandi Standard SSL CA 2/organizationName=Gandi/stateOrProvinceName=Paris/countryName=FR
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2015-12-21T00:00:00
| Not valid after:  2018-03-19T23:59:59
| MD5:   c3a7 e0ed 388f 87cb ec7f fd3e 71f2 1c3e
|_SHA-1: 5196 ecf5 7aed 139f a511 735b bfb5 7534 df63 41ba

Nmap done: 1 IP address (1 host up) scanned in 2.31 seconds
  • 2
    If you need to see the cert's fingerprints then this command is far better than the curl -v suggestions in other answers. – Bart B Feb 12 '20 at 12:27
  • This is the only one in this thread showing the subject alternative names for the certificate. – Ozymandias Nov 4 '20 at 20:16
  • Of all the other solutions (why is this basic operation so hard?), this is the least cumbersome. It's likely the one Trinity will prefer, too. – Mike Andrews Dec 9 '20 at 14:16

Depends on what kind of information you want, but:

openssl s_client -showcerts -connect gnupg.org:443

should give you most, although not as nicely human readable like Chrome presents it.

  • 2
    Unfortunately, very little of the certificate data is presented in human-readable format by that command. – Håkan Lindqvist Jan 23 '15 at 22:38
  • 10
    I disagree with previous comment, this command tells me what I need to know and is very useful. +1 for answer. – camdixon May 12 '17 at 18:47
  • If you specifically want to test for TLS 1.2 you can add -tls1_2 – camdixon May 12 '17 at 18:53
  • @Trismegistos I don't believe that is a thing. You can certainly pipe the certificate in the output here into openssl x509 (which does have a -text option where it prints a human readable representation), like in serverfault.com/a/661982/183318 But if you want to improve this answer, you really shouldn't address me as I did not write it. – Håkan Lindqvist Feb 1 at 13:16

For completeness: if you have installed on your system Java 7 or higher

 keytool -printcert -sslserver $host[:$port]

shows the chain (as served) with nearly all details in a mostly rather ugly format.

Whether you should have Java installed on your system I do not answer.

  • 1
    brilliant, much more useful default output than openssl (which needs decoding). – simon May 13 '19 at 19:50
  • This seems to be the easiest way to check all domains supported by ssl-cert `keytool -printcert -sslserver smth.yourdomain.com | grep -E 'Owner|DNSName' this will show "default domain name" of the cert AND ALTERNATIVE DOMAIN NAMES of the cert – Dimitry K Dec 17 '19 at 11:06

If you only want the expiry date (which isn't exactly the answer but is 9/10 what people use the Chrome cert details for), you can use:

echo | openssl s_client -connect google.com:443 2>/dev/null | openssl x509 -noout -enddate

Useful for scripts etc.

c4urself@eos ~ → which ssl_expiry
ssl_expiry () {
  echo | openssl s_client -connect ${1}:443 2> /dev/null | openssl x509 -noout -enddate
c4urself@eos ~ → ssl_expiry google.com
notAfter=Jun 12 16:54:00 2018 GMT

To check for SSL certificate details, I use the following command line tool ever since it's become available:


It's great to double-check you have all info correct for re-issuing certs or validating existing ones, and also as few dependencies AND it requires no setup.

This is what the first few lines of the output look like:

$ ./check_certificate_chain.py gnupg.org 443

>> Certificate Chain:

 [+]*       OU=Domain Control Validated, OU=Gandi Standard SSL, CN=gnupg.org
 [+]**      C=FR, O=GANDI SAS, CN=Gandi Standard SSL CA
 [+]***     C=US, ST=UT, L=Salt Lake City, O=The USERTRUST Network, OU=http://www.usertrust.com, CN=UTN-USERFirst-Hardware

>> Certificate Information:

- [Subject]:        OU=Domain Control Validated, OU=Gandi Standard SSL, CN=gnupg.org
- [Issuer]:     C=FR, O=GANDI SAS, CN=Gandi Standard SSL CA
- [Valid from]:     Mar 18 00:00:00 2014 GMT
- [Valid until]:    Mar 18 23:59:59 2016 GMT
- [Authority]:      Is not a CA
- [Version]:        2
- [Serial No.]:     43845251655098616578492338727643475746
- [X.509 Extension Details]:
  -- [x509_authorityKeyIdentifier]:

That output is followed by the whole certificate chain at the same level of detail.

What I like that instead of being a ssl-centric cli tool like openssl's s_client, this one tries to just do the one job we need most of the time. Of course openssl is more flexible (i.e. also checking clientcerts, imaps on odd ports, etc) - but I don't always need that.

Alternatively, if you have time to dig in & setup or appreciate more features, there's the bigger tool named sslyze (not using it since dependencies and install...)


If you want to do this in Windows you can use PowerShell with the following function:

function Retrieve-ServerCertFromSocket ($hostname, $port=443, $SNIHeader, [switch]$FailWithoutTrust)
    if (!$SNIHeader) {
        $SNIHeader = $hostname

    $cert = $null
    try {
        $tcpclient = new-object System.Net.Sockets.tcpclient

        #Authenticate with SSL
        if (!$FailWithoutTrust) {
            $sslstream = new-object System.Net.Security.SslStream -ArgumentList $tcpclient.GetStream(),$false, {$true}
        } else {
            $sslstream = new-object System.Net.Security.SslStream -ArgumentList $tcpclient.GetStream(),$false

        $cert =  [System.Security.Cryptography.X509Certificates.X509Certificate2]($sslstream.remotecertificate)

     } catch {
        throw "Failed to retrieve remote certificate from $hostname`:$port because $_"
     } finally {
        if ($sslStream) {$sslstream.close()}
        if ($tcpclient) {$tcpclient.close()}        
    return $cert

This allows you to do some neat things like

#Save to file and open 
Retrieve-ServerCertFromSocket www.wrish.com 443 | Export-Certificate -FilePath C:\temp\test.cer ; start c:\temp\test.cer

#Display the cert details
Retrieve-ServerCertFromSocket www.wrish.com 443 | fl subject,*not*,Thumb*,ser*

I use a shell script for this. It's just a wrapper around the openssl command that saves me from remembering the syntax.

It provides options for parsing out most of the certificate information I'm typically interested in, or display raw openssl output.

Can either query a local certificate file, or a remote server.


$ ssl-cert-info --help
Usage: ssl-cert-info [options]

This shell script is a simple wrapper around the openssl binary. It uses
s_client to get certificate information from remote hosts, or x509 for local
certificate files. It can parse out some of the openssl output or just dump all
of it as text.


  --all-info   Print all output, including boring things like Modulus and 

  --alt        Print Subject Alternative Names. These will be typically be 
               additional hostnames that the certificate is valid for.

  --cn         Print commonName from Subject. This is typically the host for 
               which the certificate was issued.

  --debug      Print additional info that might be helpful when debugging this

  --end        Print certificate expiration date. For additional functionality
               related to certificate expiration, take a look at this script:

  --dates      Print start and end dates of when the certificate is valid.

  --file       Use a local certificate file for input.

  --help       Print this help message.

  --host       Fetch the certificate from this remote host.

  --issuer     Print the certificate issuer.

  --most-info  Print almost everything. Skip boring things like Modulus and

  --option     Pass any openssl option through to openssl to get its raw

  --port       Use this port when conneting to remote host. If ommitted, port
               defaults to 443.

  --subject    Print the certificate Subject -- typically address and org name.


  1. Print a list of all hostnames that the certificate used by amazon.com 
     is valid for.

     ssl-cert-info --host amazon.com --alt

  2. Print issuer of certificate used by smtp.gmail.com. Fetch certficate info
     over port 465.

     ssl-cert-info --host smtp.gmail.com --port 465 --issuer
         countryName               = US
         organizationName          = Google Inc
         commonName                = Google Internet Authority G2

  3. Print valid dates for the certificate, using a local file as the source of 
     certificate data. Dates are formatted using the date command and display
     time in your local timezone instead of GMT.

     ssl-cert-info --file /path/to/file.crt --dates
     valid from: 2014-02-04 16:00:00 PST
     valid till: 2017-02-04 15:59:59 PST

  4. Print certificate serial number. This script doesn't have a special option
     to parse out the serial number, so will use the generic --option flag to
     pass '-serial' through to openssl.

     ssl-cert-info --host gmail.com --option -serial

You can get the script here: https://web.archive.org/web/20190528035412/http://giantdorks.org/alain/shell-script-to-check-ssl-certificate-info-like-expiration-date-and-subject/

  • The link is dead. – Adam Matan Nov 2 '17 at 11:07
nmap -sV -sC google.com -p 443
  • 5
    This needs a lot more explanation. – Sven Jul 27 '17 at 16:19
  • agree with need for explanation, but it does work for me, so +1 – Jeff Oct 19 '17 at 15:37

You can also try the gnutls-cli tool from https://www.gnutls.org/:

echo | gnutls-cli serverfault.com

The echo | is there to make gnutls-cli exit quickly, instead of waiting for input from stdin.

If you need the raw certificate data (in PEM format), add --print-cert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.