openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost' -addext 'subjectAltName=DNS:localhost,IP:127.0.0.1'

Category: Web App Development

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost' -addext 'subjectAltName=DNS:localhost,IP:127.0.0.1'

Generate a self-signed cert with SANs

Creates a 2048-bit RSA key and a self-signed certificate valid for a year, with the subject alternative names that modern browsers require. The -nodes flag keeps the key unencrypted so servers can load it without a passphrase. Browsers still warn because no trusted CA signed it.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.