One command: key + self-signed cert
This creates a 2048-bit RSA key and a self-signed certificate valid for 365 days in one step:
Output: key.pem (private key) and cert.pem (self-signed certificate).
One-liner without prompts
Pass all subject fields with -subj for use in scripts or CI pipelines:
In PowerShell replace ^ with a backtick ` for line continuation.
Self-signed cert with Subject Alternative Names
Modern browsers require SAN extensions. Without them you will see certificate errors even after trusting the cert. Create a config file cert.cnf:
Then generate the certificate:
Add the certificate to Windows trusted roots
To avoid browser warnings on your local machine, import the cert into the Windows Trusted Root store:
Or via GUI: double-click cert.pem → Install Certificate → Local Machine → Trusted Root Certification Authorities.
Inspect the certificate
Self-signed cert questions
Why does Chrome still show a warning after trusting the cert?
How do I renew a self-signed certificate?
-days 365. If you want to keep the same key, use the two-step method: openssl x509 -req -in request.csr -signkey key.pem -out cert.pem -days 365.What is the difference between -x509 and a CA-signed cert?
-x509 flag makes OpenSSL sign the certificate itself with the same key, creating a self-signed cert. A CA-signed cert is signed by a trusted Certificate Authority — browsers trust it automatically without any import step.Can I use the cert for multiple domains?
DNS.N entries to the [alt_names] section in the config file. Each entry covers one domain or subdomain.Need a CA-signed certificate?
Generate a CSR and submit it to a public CA like Let's Encrypt.
Related guides