Skip to content

Instantly share code, notes, and snippets.

@meenakshi-koushik
Created June 9, 2025 12:34
Show Gist options
  • Save meenakshi-koushik/41c7a0f97f5f2987a6d54d2c8195b674 to your computer and use it in GitHub Desktop.
Save meenakshi-koushik/41c7a0f97f5f2987a6d54d2c8195b674 to your computer and use it in GitHub Desktop.
Generate certificates with arbitrary validity
#!/usr/bin/bash
# Usage:
# gen.sh <STARTDATE> <ENDDATE>
# the dates are in YYYYMMDDhhmmssZ format and are UTC timestamps
# Example:
# gen.sh 20250609000000Z 20250630000000Z
STARTDATE="${1:-20250101000000Z}"
ENDDATE="${2:-20250101000000Z}"
# Generate private key
openssl genrsa -out server.key 2048
# Generate CSR with specific hostname
openssl req -new -key server.key -out server.csr -subj "/CN=your-hostname.example.com"
# Generate self-signed certificate with specific expiry
openssl x509 -req \
-not_before "${STARTDATE}" \
-not_after "${ENDDATE}" \
-in server.csr \
-signkey server.key \
-out server.crt \
-extensions v3_req \
-extfile <(printf "[v3_req]\nsubjectAltName=DNS:your-hostname.example.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment