Skip to content

Instantly share code, notes, and snippets.

@alsunseri
Last active October 23, 2021 01:13
show SSL certificate file serial number via CLI
#!/usr/bin/env bash
# Display an error message if the command does not include a filename
# Exit the shell script with a status of 1 using exit 1 command.
[ $# -eq 0 ] && { echo "Usage: $0 certfilename"; exit 1; }
CERTFILE=$1
openssl x509 -noout -serial -in $CERTFILE
# for formatting the output in quad see
# https://unix.stackexchange.com/questions/533194/how-to-extract-serial-from-ssl-certificate
# openssl x509 -noout -serial -in cert.pem | cut -d'=' -f2 | sed 's/../&:/g;s/:$//'
# openssl x509 -noout -serial -in test2.crt | sed 's/.*=//g;s/../&:/g;s/:$//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment