Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a SSL CRT file in PEM format. Is there a way that I can extract the common name (CN) from the certificate from the command line?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

If you have openssl installed you can run:

openssl x509 -noout -subject -in server.pem
share|improve this answer
You can extract the CN out of the subject with: openssl x509 -noout -subject -in server.pem | sed -n '/^subject/s/^.*CN=//p' –  Matthew Buckett Dec 4 '14 at 12:09
certtool -i < whatever.pem

Notice that's directing the file to standard input via <, not using it as argument. This will print the whole certificate out, the CN is near the top:

X.509 Certificate Information:
    Version: 3
    Serial Number (hex): 01
    Issuer: CN=goldilocks

certtool is part of gnutls, if it is not installed just search for that. GnuTLS is a little nicer than OpenSSL, IMO.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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