openssl req -new -x509 -key key.pem -out cert.pem -days 365 -subj '/CN=example.com'

Category: Security & Hardening

openssl req -new -x509 -key key.pem -out cert.pem -days 365 -subj '/CN=example.com'

Create a self-signed certificate from an existing key

Issues a self-signed X.509 certificate for CN=example.com using key.pem, valid for 365 days. Self-signed certs work for testing and internal services but browsers distrust them. For a public site, use the same key to generate a CSR and have it signed by a CA, for example via certbot.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.