How to get common name (CN) from SSL certificate using openssl command

https://‮‬www.lautturi.com
How to get common name (CN) from SSL certificate using openssl command

You can use the openssl x509 -in command to view the details of an SSL certificate, including the common name (CN).

For example, to view the details of an SSL certificate stored in a file called cert.pem, you can use the following command:

openssl x509 -in cert.pem -text -noout

This will display the full details of the certificate, including the common name. The common name is typically located in the "Subject" field, which will look something like this:

Subject: CN=www.example.com

In this example, the common name is "www.example.com".

You can use the awk command to extract the common name from the output of the openssl command. For example, the following command will print the common name of the certificate:

openssl x509 -in cert.pem -text -noout | awk '/Subject:/ {print $NF}'

This will output the common name (CN) of the certificate, without any other information.

Created Time:2017-10-28 21:39:03  Author:lautturi