Skip to content

Linux & shell: TLS & certificates (openssl)

8 Linux & shell commands: TLS & certificates (openssl). Click a command to see what each part does.

Index
8 items
Click a command to see what each part does.

TLS & certificates (openssl)8

  • openssl s_client -connect <host>:443 -servername <host> -showcerts </dev/nullShow a server's certificate and chain

    What each part does

    1. s_client -connect <host>:443open a TLS connection
    2. -servername <host>send SNI, so you get the right certificate on shared IPs
    3. -showcertsprint every certificate the server sends
    4. </dev/nullclose the connection right after the handshake
  • openssl s_client -connect <host>:443 -servername <host> </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -datesWhen does a site's certificate expire?

    What each part does

    1. openssl s_client ...fetch the certificate
    2. | openssl x509 -nooutparse it without printing the encoded certificate
    3. -subject -issuer -dateswho it is for, who signed it, notBefore and notAfter
  • openssl x509 -in <cert>.pem -noout -textRead a certificate file

    What each part does

    1. x509 -in <cert>.pema PEM certificate file
    2. -noout -textfull details: subject, SANs (DNS names), validity, key size
  • openssl x509 -noout -pubkey -in <cert>.pem | sha256sum; openssl pkey -pubout -in <key>.pem | sha256sumDoes this key belong to this certificate?

    What each part does

    1. x509 -pubkeypublic key from the certificate
    2. pkey -puboutpublic key derived from the private key
    3. sha256sumthe two hashes must be identical
  • openssl req -new -newkey rsa:2048 -nodes -keyout <name>.key -out <name>.csr -subj "/CN=<domain>"Create a private key and a CSR

    What each part does

    1. req -newnew certificate signing request
    2. -newkey rsa:2048 -nodesgenerate a 2048-bit key, not encrypted with a passphrase
    3. -keyout / -outwhere to write the key and the CSR
    4. -subj "/CN=<domain>"subject; add -addext "subjectAltName=DNS:<domain>" for SANs
  • openssl req -x509 -newkey rsa:2048 -nodes -days 365 -keyout <name>.key -out <name>.crt -subj "/CN=<domain>"Self-signed certificate for testing

    What each part does

    1. req -x509output a self-signed certificate instead of a CSR
    2. -days 365valid for a year
  • openssl verify -CAfile <ca-bundle>.pem <cert>.pemCheck a certificate against a CA bundle

    What each part does

    1. openssl verifyOK if the chain validates; otherwise the reason (expired, unable to get issuer)
    2. -CAfiletrusted CA and intermediates
  • openssl s_client -connect <host>:443 -tls1_2 </dev/null; openssl s_client -connect <host>:443 -tls1_3 </dev/nullWhich TLS versions does a server accept?

    What each part does

    1. -tls1_2 / -tls1_3force one protocol version; a handshake failure means it's not supported

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…