$linuxjunkies
>

openssl-x509(1)

Display and sign X.509 certificates, including extracting fields, converting formats, and validating certificate chains.

UbuntuDebianFedoraArch

Synopsis

openssl x509 [OPTIONS] [INFILE] [OUTFILE]

Description

The openssl x509 command is a certificate utility that reads and processes X.509 certificates in PEM or DER format. It can display certificate information, extract public keys, convert between formats, sign certificates with a CA key, and verify certificate chains.

Common uses include viewing certificate details, converting between PEM and DER formats, extracting the public key or subject alternative names, and self-signing certificates during the CA setup process.

Common options

FlagWhat it does
-in FILEInput certificate file (PEM or DER format); defaults to stdin
-out FILEOutput file for the certificate or extracted data; defaults to stdout
-textPrint certificate in human-readable text format
-nooutSuppress PEM encoding of the certificate in output (useful with -text or -subject)
-subjectPrint the certificate subject name
-issuerPrint the certificate issuer name
-datesPrint the certificate notBefore and notAfter validity dates
-pubkeyExtract and print the public key from the certificate
-fingerprintPrint the certificate fingerprint (SHA-1 by default)
-inform PEM|DERInput certificate format (PEM is default)
-outform PEM|DER|TEXTOutput certificate format (PEM is default)
-CAkey FILECA private key file for signing the certificate request

Examples

Display the full certificate details in human-readable text format

openssl x509 -in cert.pem -text -noout

Extract and print only the subject distinguished name

openssl x509 -in cert.pem -subject -noout

Show the certificate validity dates (notBefore and notAfter)

openssl x509 -in cert.pem -dates -noout

Print the certificate SHA-1 fingerprint for identification

openssl x509 -in cert.pem -fingerprint -noout

Extract the public key from the certificate

openssl x509 -in cert.pem -pubkey -noout

Convert a DER-format certificate to PEM format

openssl x509 -in cert.der -inform DER -outform PEM -out cert.pem

Sign a certificate signing request (CSR) with a CA certificate and private key

openssl x509 -req -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server.crt -days 365

Display both the issuer and subject names of the certificate

openssl x509 -in cert.pem -issuer -subject -noout

Related commands