Skip to content
Log In Sign Up info@muvcloud.com

The Command

On Ubuntu and Debian:

sudo openssl req -x509 -newkey rsa:2048 -sha256 -days 365 -noenc \
  -keyout /etc/ssl/private/example.com.key \
  -out /etc/ssl/certs/example.com.crt \
  -subj "/CN=example.com" \
  -addext "subjectAltName=DNS:example.com,DNS:www.example.com,IP:203.0.113.10"
sudo chmod 600 /etc/ssl/private/example.com.key

On AlmaLinux and Rocky Linux, use /etc/pki/tls/private/ for the key and /etc/pki/tls/certs/ for the certificate. The command needs no answers: -subj fills in the subject.

What Each Option Does

OptionMeaning
-x509Make a certificate, not a request
-newkey rsa:2048Create a new 2048-bit RSA key
-sha256Sign with SHA-256
-days 365Valid for one year
-noencNo passphrase on the key
-subjSubject, here only the name
-addextAdds an extension

The subjectAltName extension matters most. Browsers check the requested name against this list and ignore the common name, so a certificate without it fails even in a test. List every name and IP address that clients will use. Without -noenc, the key gets a passphrase and the web server asks for it at every start. -noenc exists from OpenSSL 3.0, which every current release named here ships; the older spelling -nodes still works but is deprecated. Check your release with how to check the OpenSSL version.

For a smaller, faster ECDSA key, replace the key option with -newkey ec -pkeyopt ec_paramgen_curve:prime256v1.

Check the Certificate

openssl x509 -in /etc/ssl/certs/example.com.crt -noout -subject -dates -ext subjectAltName

The output shows the subject, the start and end dates, and the alternative names. If the names list is missing, the -addext part was not applied.

Use It in Nginx

server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate /etc/ssl/certs/example.com.crt;
    ssl_certificate_key /etc/ssl/private/example.com.key;
    root /var/www/example.com;
}

Test and reload:

sudo nginx -t && sudo systemctl reload nginx

In Apache, the same two files go in SSLCertificateFile and SSLCertificateKeyFile.

What Browsers and Clients Do

Browsers show a full-page warning, because no trusted authority signed the certificate. Command-line tools refuse the connection: curl needs --cacert /etc/ssl/certs/example.com.crt, or -k for a one-off test. On your own computer you can import the certificate, never the key, into the browser's or the system's trust store to remove the warning for yourself. For several internal services, a small private certificate authority whose root you distribute once is easier to manage than many single certificates.

When a Self-Signed Certificate Fits

  • Testing: a staging server or a local setup where only you connect.
  • Internal services: an admin tool, a database, or a message queue reached only by your own clients, which you can configure to trust the certificate.
  • An origin behind a proxy that does not verify: some CDN settings encrypt to the origin without checking the certificate. A strict setting needs a trusted or provider-issued origin certificate instead, or visitors see Cloudflare error 526; see Cloudflare error 525 for handshake problems between the proxy and the origin.
  • Not for a public website: visitors see a warning and most leave. Use a Let's Encrypt certificate there, as in Certbot with Nginx.

Keep the Private Key Private

Give the key mode 600, owned by root. Never paste it into a chat, a support ticket, or a repository; a .gitignore rule for *.key helps. The certificate itself is public and can be shared. If a key leaks, create a new key and certificate and replace both everywhere.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations