Blog › Security · Published 2026-11-26

How to generate a self-signed SSL certificate with OpenSSL

A self-signed certificate is fine for local testing. Browsers will warn about it because no trusted authority signed it, so do not use it for a public website.

openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365

OpenSSL asks for the name fields. Use the host name you will visit (for example localhost) as the Common Name.

Check the result

openssl x509 -in cert.pem -text -noout

For a real site

Use a certificate from a public authority. Many web servers, such as Caddy, can get free certificates automatically.

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles