OPENSSL-X509(1ossl)
β¨ NAME β¨
openssl-x509 β Certificate display and signing command. The manpage itself is OPENSSL-X509(1ossl), but weβre just gonna call it openssl-x509, bestie π
π SYNOPSIS π
openssl x509 [-help] [-in filename|uri] [-passin arg] [-new]
[-x509toreq] [-req] [-copy_extensions arg] [-inform DER|PEM] [-vfyopt
nm:v] [-key filename|uri] [-keyform DER|PEM|P12|ENGINE] [-signkey
filename|uri] [-out filename] [-outform DER|PEM] [-nocert] [-noout]
[-dateopt] [-text] [-certopt option] [-fingerprint] [-alias] [-serial]
[-startdate] [-enddate] [-dates] [-subject] [-issuer] [-nameopt option]
[-email] [-hash] [-subject_hash] [-subject_hash_old] [-issuer_hash]
[-issuer_hash_old] [-ext extensions] [-ocspid] [-ocsp_uri] [-purpose]
[-pubkey] [-modulus] [-checkend num] [-checkhost host] [-checkemail
host] [-checkip ipaddr] [-set_serial n] [-next_serial] [-not_before
date] [-not_after date] [-days arg] [-preserve_dates] [-set_issuer arg]
[-set_subject arg] [-subj arg] [-force_pubkey filename] [-clrext]
[-extfile filename] [-extensions section] [-sigopt nm:v] [-badsig]
[-digest] [-CA filename|uri] [-CAform DER|PEM|P12] [-CAkey filename|uri]
[-CAkeyform DER|PEM|P12|ENGINE] [-CAserial filename] [-CAcreateserial]
[-trustout] [-setalias arg] [-clrtrust] [-addtrust arg] [-clrreject]
[-addreject arg] [-rand files] [-writerand file] [-engine id] [-provider
name] [-provider-path path] [-provparam [name:]key=value] [-propquery
propq]
π DESCRIPTION π
Okay so this command is the ultimate multi-purpose certificate-handling bestie. It can print certificate info, convert certs into various forms, edit certificate trust settings, generate certificates from scratch or from certification requests, and then self-sign them or sign them like a tiny βmicro CAβ. Iconic, honestly π
Generated certificates bear X.509 version 3. Unless specified otherwise, key identifier extensions are included as described in x509v3_config(5).
Because there are so many options, theyβre split up into various sections. Buckle up, babe π
π οΈ OPTIONS π οΈ
π§° Input, Output, and General Purpose Options π§°
-helpβ Print out a usage message. Your little βwhat do I even doβ lifeline π«Ά-in filename|uriβ This specifies the input to read a certificate from, or the input file for reading a certificate request if the-reqflag is used. In both cases this defaults to standard input.
Watch out: this option cannot be combined with the -new flag.
-passin argβ The key and certificate file password source. For more information about the format ofarg, seeopenssl-passphrase-options(1).-newβ Generate a certificate from scratch, not using an input certificate or certificate request. So this excludes the-inand-reqoptions. Instead, the-set_subjectoption needs to be given. The public key to include can be given with the-force_pubkeyoption and defaults to the key given with the-key(or-signkey) option, which implies self-signature. Fresh cert, no input drama β¨-x509toreqβ Output a PKCS#10 certificate request (rather than a certificate). The-key(or-signkey) option must be used to provide the private key for self-signing; the corresponding public key is placed in thesubjectPKInfofield.
X.509 extensions included in a certificate input are not copied by default. X.509 extensions to be added can be specified using the -extfile option.
-reqβ By default a certificate is expected on input. With this option a PKCS#10 certificate request is expected instead, which must be correctly self-signed.
X.509 extensions included in the request are not copied by default. X.509 extensions to be added can be specified using the -extfile option.
-copy_extensions argβ Determines how to handle X.509 extensions when converting from a certificate to a request using the-x509toreqoption, or converting from a request to a certificate using the-reqoption. Ifargisnoneor this option is not present, then extensions are ignored. Ifargiscopyorcopyall, then all extensions are copied, except that subject identifier and authority key identifier extensions are not taken over when producing a certificate request.
The -ext option can be used to further restrict which extensions to copy.
-inform DER|PEMβ The input file format to use; by defaultPEMis tried first. Seeopenssl-format-options(1)for details.-vfyopt nm:vβ Pass options to the signature algorithm during verify operations. Names and values of these options are algorithm-specific.-key filename|uriβ This option provides the private key for signing a new certificate or certificate request. Unless-force_pubkeyis given, the corresponding public key is placed in the new certificate or certificate request, resulting in a self-signature.
No cap: this option cannot be used in conjunction with the -CA option.
It sets the issuer name to the subject name (i.e., makes it self-issued). Unless the -preserve_dates option is supplied, it sets the validity start date to the current time and the end date to a value determined by the -days option. Start date and end date can also be explicitly supplied with options -not_before and -not_after.
-signkey filename|uriβ This option is an alias of-key. Same vibe, different name π«-keyform DER|PEM|P12|ENGINEβ The key input format; unspecified by default. Seeopenssl-format-options(1)for details.-out filenameβ This specifies the output filename to write to, or standard output by default.-outform DER|PEMβ The output format; the default isPEM. Seeopenssl-format-options(1)for details.-nocertβ Do not output a certificate (except for printing as requested by below options).-nooutβ This option prevents output except for printing as requested by below options.
π¨οΈ Certificate Printing Options π¨οΈ
Note: the-aliasand-purposeoptions are also printing options but are described in the βTrust Settingsβ section.
-dateoptβ Specify the date output format. Values are:rfc_822andiso_8601. Defaults torfc_822.-textβ Prints out the certificate in text form. Full details are printed, including the public key, signature algorithms, issuer and subject names, serial number, any extensions present, and any trust settings. Itβs giving βtell me everythingβ π-certopt optionβ Customise the print format used with-text. The option argument can be a single option or multiple options separated by commas. The-certoptswitch may also be used more than once to set multiple options. See the βText Printing Flagsβ section for more information.-fingerprintβ Calculates and prints the digest of the DER encoded version of the entire certificate (see digest options). This is commonly called a βfingerprintβ. Because of the nature of message digests, the fingerprint of a certificate is unique to that certificate, and two certificates with the same fingerprint can be considered to be the same.-aliasβ Prints the certificate βaliasβ (nickname), if any.-serialβ Prints the certificate serial number.-startdateβ Prints out the start date of the certificate, that is thenotBeforedate.-enddateβ Prints out the expiry date of the certificate, that is thenotAfterdate.-datesβ Prints out the start and expiry dates of a certificate.-subjectβ Prints the subject name.-issuerβ Prints the issuer name.-nameopt optionβ This specifies how the subject or issuer names are displayed. Seeopenssl-namedisplay-options(1)for details.-emailβ Prints the email address(es) if any.-hashβ Synonym for-subject_hashfor backward compatibility reasons.-subject_hashβ Prints the βhashβ of the certificate subject name. This is used in OpenSSL to form an index to allow certificates in a directory to be looked up by subject name.-subject_hash_oldβ Prints the βhashβ of the certificate subject name using the older algorithm as used by OpenSSL before version 1.0.0.-issuer_hashβ Prints the βhashβ of the certificate issuer name.-issuer_hash_oldβ Prints the βhashβ of the certificate issuer name using the older algorithm as used by OpenSSL before version 1.0.0.-ext extensionsβ Prints out the certificate extensions in text form. Can also be used to restrict which extensions to copy. Extensions are specified with a comma separated string, e.g.,"subjectAltName, subjectKeyIdentifier". See thex509v3_config(5)manual page for the extension names.-ocspidβ Prints the OCSP hash values for the subject name and public key.-ocsp_uriβ Prints the OCSP responder address(es) if any.-purposeβ This option performs tests on the certificate extensions and outputs the results. For a more complete description see βCertificate Extensionsβ inopenssl-verification-options(1).-pubkeyβ Prints the certificateβsSubjectPublicKeyInfoblock inPEMformat.-modulusβ This option prints out the value of the modulus of the public key contained in the certificate.
π Certificate Checking Options π
-checkend argβ Checks if the certificate expires within the nextargseconds and exits nonzero if yes it will expire or zero if not.-checkhost hostβ Check that the certificate matches the specified host.-checkemail emailβ Check that the certificate matches the specified email address.-checkip ipaddrβ Check that the certificate matches the specified IP address.
π Certificate Output Options π
-set_serial nβ Specifies the serial number to use. This option can be used with the-key,-signkey, or-CAoptions. If used in conjunction with the-CAoption, the serial number file (as specified by the-CAserialoption) is not used.
The serial number can be decimal or hex (if preceded by 0x).
-next_serialβ Set the serial to be one more than the number in the certificate.-not_before dateβ This allows the start date to be explicitly set. The format of the date isYYMMDDHHMMSSZ(the same as an ASN1UTCTimestructure), orYYYYMMDDHHMMSSZ(the same as an ASN1GeneralizedTimestructure). In both formats, secondsSSand timezoneZmust be present. Alternatively, you can also use"today".
Do not use this together with the -preserve_dates option.
-not_afterdate β okay so this one lets you hard-set the expiry date yourself, no defaulting, no vibes-based guessing π The date format isYYMMDDHHMMSSZ(same shape as an ASN1UTCTimestructure) orYYYYMMDDHHMMSSZ(same shape as an ASN1GeneralizedTimestructure). In both formats the secondsSSand the timezoneZmust be present β no skipping them, bestie, they're not optional. You can also literally just write"today"and it slays.
Heads up: you cannot use this together with the-preserve_datesoption. Also, this one overrides the-daysoption. So don't be out here setting both and acting surprised π
-daysarg β sets how many days from today a freshly generated certificate stays valid before it expires. Default is30π
Cannot be used together with the-preserve_datesoption. And if-not_afteris set, that explicit expiry date wins. Periodt.
-preserve_datesβ when you're signing a certificate, this keeps thenotBeforeandnotAfterdates from any input certificate exactly as they are, instead of shifting them to the current time and duration. Iconic for when the original dates matter. Cannot be used together with the options-days,-not_beforeand-not_afterπ«-set_issuerarg β when a certificate gets created, this sets its issuer name to whatever value you give it.
For how the arg has to be formatted, go look at -set_subject below β same rules, iykyk.
-set_subjectarg β when a certificate is created, this sets its subject name to the value you give. And when the certificate is self-signed, the issuer name gets set to that same value too β unless you've also passed-set_issuer, which overrides it.
The arg must be formatted like this:
/type0=value0/type1=value1/type2=...
Special characters can be escaped with \ (backslash), and whitespace is retained (yes, really, it's kept πΈ). Empty values are permitted, but then the corresponding type just won't be included in the certificate. Giving a single / gives you an empty sequence of RDNs (a NULL-DN). Multi-valued RDNs get formed by putting a + character instead of a / between the AttributeValueAssertions (AVAs) that specify the members of the set. Example, bestie:
"/DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe"
This option can be used with the -new and -force_pubkey options to create a brand new certificate without providing an input certificate or certificate request. Main character energy: making something out of nothing β¨
-subjarg β this is just an alias of-set_subject. Same thing, shorter name, we love convenience π-force_pubkeyfilename β when a new certificate or certificate request is created, this sets its public key to the given key instead of the key sitting in the input or the one given with the-key(or-signkey) option. And if the input contains no public key but does contain a private key, its public part gets used.
This option can be used in conjunction with -new and -set_subject to directly generate a certificate containing literally any public key you want π
It's also super useful for creating self-issued certificates that are not self-signed β for instance when the key can't be used for signing, such as DH.
-clrextβ when you're transforming a certificate into a new certificate, by default all certificate extensions are retained. This option stops that.
When transforming a certificate or certificate request, -clrext prevents taking over any extensions from the source. And in any case, when producing a certificate request, neither the subject identifier nor the authority key identifier extensions are included. FYI, no cap π«Ά
-extfilefilename β the configuration file that holds the certificate and request X.509 extensions you want to add.-extensionssection β the section inside the extfile to pull the X.509 extensions from. If you don't specify this option, then the extensions should either be in the unnamed (default) section, or the default section should contain a variable called"extensions"that holds the name of the section to use.
For the details of what the extension section format looks like, see the x509v3_config(5) manual page π
Unless specified otherwise, key identifier extensions are included as described in x509v3_config(5).
-sigoptnm:v β passes options to the signature algorithm during sign operations. You can give this option multiple times, no problem π Names and values you provide here are algorithm-specific.-badsigβ literally corrupts the signature before writing it out. This is useful for testing π§ͺ (yes, deliberately breaking things, on purpose, for science).-digestβ the digest to use. This affects any signing or printing option that uses a message digest, such as the-fingerprint,-key, and-CAoptions. Any digest supported by theopenssl-dgst(1)command works here. If you don't specify it, thenSHA1is used with-fingerprint, or the default digest for the signing algorithm is used β typicallySHA256β
π Micro-CA Options π
-CAfilename|uri β specifies the "CA" certificate used for signing. When it's present, this behaves like a "micro CA", like so: the subject name of the "CA" certificate gets placed as the issuer name in the new certificate, which is then signed using the "CA" key given as detailed below π
This option cannot be used in conjunction with-key(or-signkey). Not a vibe, don't do it.
This option is normally combined with the -req option referencing a CSR. Without the -req option, the input must be an existing certificate β unless the -new option is given, which generates a certificate from scratch π±
-CAformDER|PEM|P12,β the format for the CA certificate; unspecified by default. Seeopenssl-format-options(1)for the details.-CAkeyfilename|uri β sets the CA private key to sign a certificate with. This private key must match the public key of the certificate given with-CA. If you don't provide this option, then the key must already be present in the-CAinput.-CAkeyformDER|PEM|P12|ENGINEβ the format for the CA key; unspecified by default. Seeopenssl-format-options(1)for details.-CAserialfilename β sets the CA serial number file to use π
When creating a certificate with this option and with the -CA option, the certificate serial number gets stored in the given file. This file consists of one line containing an even number of hex digits with the serial number used last time. After reading that number, it's incremented and used, and the file gets updated.
The default filename is the CA certificate file's base name with .srl appended. For example, if the CA certificate file is called mycacert.pem it expects to find a serial number file called mycacert.srl.
If the -CA option is specified and neither -CAserial nor -CAcreateserial is given, and the default serial number file doesn't exist, then a random number is generated β and this is the recommended practice β¨
-CAcreateserialβ with this option and the-CAoption, the CA serial number file gets created if it doesn't already exist. A random number is generated, used for the certificate, and saved into the serial number file determined as described above π²
π Trust Settings π
A trusted certificate is just an ordinary certificate that has several extra pieces of information attached to it β stuff like the permitted and prohibited uses of the certificate, and possibly an "alias" (a nickname).
Normally, when a certificate is being verified, at least one certificate must be "trusted". By default a trusted certificate must be stored locally and must be a root CA: any certificate chain ending in this CA is then usable for any purpose π
Trust settings currently are only used with a root CA. They allow finer control over what purposes the root CA can be used for. For example, a CA may be trusted for SSL client but not SSL server use.
See openssl-verification-options(1) for more info on what trust settings actually mean π
Future versions of OpenSSL will recognize trust settings on any certificate β not just root CAs. Big changes coming, bestie.
-trustoutβ marks any certificate PEM output as a<trusted>certificate rather than ordinary. An ordinary or trusted certificate can both be input, but by default an ordinary certificate is output and any trust settings get discarded. With the-trustoutoption, a trusted certificate is output. Oh, and a trusted certificate is automatically output if any trust settings are modified π-setaliasarg β sets the "alias" of the certificate. This lets the certificate be referred to using a nickname, for example"Steve's Certificate"π-clrtrustβ clears all the permitted or trusted uses of the certificate π§Ή-addtrustarg β adds a trusted certificate use. Any object name can go here, but currently onlyclientAuth,serverAuth,emailProtection, andanyExtendedKeyUsageare defined. As of OpenSSL 1.1.0, that last one blocks all purposes when rejected, or enables all purposes when trusted. Other OpenSSL applications may define additional uses π-clrrejectβ clears all the prohibited or rejected uses of the certificate π§Ό-addrejectarg β adds a prohibited trust anchor purpose. It accepts the same values as the-addtrustoption.
πΈ Generic options πΈ
-randfiles,-writerandfile β see "Random State Options" inopenssl(1)for details π²-engineid β see "Engine Options" inopenssl(1). This option is deprecated β οΈ (yes, we're retiring it, no drama).-providername-provider-pathpath-provparam[name:]key=value-propquerypropq
All four of those: see "Provider Options" in openssl(1), provider(7), and property(7) π
β¨ Text Printing Flags β¨
As well as customising the name printing format, you can also customise the actual fields printed using the certopt option when the text option is present. Default behaviour is to print all the fields.
compatibleβ use the old format. This is equivalent to specifying no printing options at all.no_headerβ don't print header information, i.e. the lines saying"Certificate"and"Data".no_versionβ don't print out the version number.no_serialβ don't print out the serial number.no_signameβ don't print out the signature algorithm used.no_validityβ don't print the validity, that is thenotBeforeandnotAfterfields.no_subjectβ don't print out the subject name.no_issuerβ don't print out the issuer name.no_pubkeyβ don't print out the public key.no_sigdumpβ don't give a hexadecimal dump of the certificate signature.no_auxβ don't print out certificate trust information.no_extensionsβ don't print out any X509V3 extensions.ext_defaultβ retain default extension behaviour: attempt to print out unsupported certificate extensions.ext_errorβ print an error message for unsupported certificate extensions π¨ext_parseβ ASN1 parse unsupported extensions.ext_dumpβ hex dump unsupported extensions π§ca_defaultβ the value used byopenssl-ca(1), equivalent tono_issuer,no_pubkey,no_header, andno_version.
β¨ EXAMPLES β¨
Okay bestie, examples time β this is where it gets practical π Tiny but crucial note: in these examples, the \ means the example should be all on one line.
Print the contents of a certificate:
openssl x509 -in cert.pem -noout -text
Print the βSubject Alternative Nameβ extension of a certificate:
openssl x509 -in cert.pem -noout -ext subjectAltName
Print more extensions of a certificate:
openssl x509 -in cert.pem -noout -ext subjectAltName,nsCertType
Print the certificate serial number:
openssl x509 -in cert.pem -noout -serial
Print the certificate subject name:
openssl x509 -in cert.pem -noout -subject
Print the certificate subject name in RFC2253 form:
openssl x509 -in cert.pem -noout -subject -nameopt RFC2253
Print the certificate subject name in oneline form on a terminal supporting UTF8:
openssl x509 -in cert.pem -noout -subject -nameopt oneline,-esc_msb
Print the certificate SHA1 fingerprint:
openssl x509 -sha1 -in cert.pem -noout -fingerprint
Convert a certificate from PEM to DER format:
openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
Convert a certificate to a certificate request:
openssl x509 -x509toreq -in cert.pem -out req.pem -key key.pem
Convert a certificate request into a self-signed certificate using extensions for a CA:
openssl x509 -req -in careq.pem -extfile openssl.cnf -extensions v3_ca \
-key key.pem -out cacert.pem
Sign a certificate request using the CA certificate above and add user certificate extensions:
openssl x509 -req -in req.pem -extfile openssl.cnf -extensions v3_usr \
-CA cacert.pem -CAkey key.pem -CAcreateserial
Set a certificate to be trusted for SSL client use and change set its alias to βSteve's Class 1 CAβ
openssl x509 -in cert.pem -addtrust clientAuth \
-setalias "Steve's Class 1 CA" -out trust.pem
πΈ NOTES πΈ
The conversion to UTF8 format used with the name options assumes that T61Strings use the ISO8859-1 character set. This is wrong but Netscape and MSIE do this as do many certificates. So although this is incorrect it is more likely to print the majority of certificates correctly. Lowkey iconic mess, ngl π
The -email option searches the subject name and the subject alternative name extension. Only unique email addresses will be printed out: it will not print the same address more than once. No duplicates, periodt π
π BUGS π
It is possible to produce invalid certificates or requests by specifying the wrong private key, using unsuitable X.509 extensions, or using inconsistent options in some cases: these should be checked. Do not just send it and pray bestie, fr fr π
There should be options to explicitly set such things as start and end dates rather than an offset from the current time.
π SEE ALSO π
openssl(1)openssl-req(1)openssl-ca(1)openssl-genrsa(1)openssl-gendsa(1)openssl-verify(1)x509v3_config(5)
π¦ HISTORY π¦
The hash algorithm used in the -subject_hash and -issuer_hash options before OpenSSL 1.0.0 was based on the deprecated MD5 algorithm and the encoding of the distinguished name. In OpenSSL 1.0.0 and later it is based on a canonical version of the DN using SHA1. This means that any directories using the old form must have their links rebuilt using openssl-rehash(1) or similar. Glow-up with consequences, honestly β¨
The -signkey option has been renamed to -key in OpenSSL 3.0, keeping the old name as an alias.
The -engine option was deprecated in OpenSSL 3.0.
The -C option was removed in OpenSSL 3.0.
Since OpenSSL 3.2, generated certificates bear X.509 version 3, and key identifier extensions are included by default.
π COPYRIGHT π
Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the βLicenseβ). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at https://www.openssl.org/source/license.html.
Thatβs the whole page, bestie π«Ά This was OPENSSL-X509(1ossl), version 3.5.0, dated 2026-09-25 β slay and stay certified π
π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms