Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Key and CSR in One Command

On Debian and Ubuntu the key folder is closed to normal users, so open a root shell first and work there:

sudo -i
cd /etc/ssl/private
openssl req -new -newkey rsa:2048 -noenc \
  -keyout example.com.key -out example.com.csr \
  -subj "/O=Example Inc/CN=example.com" \
  -addext "subjectAltName=DNS:example.com,DNS:www.example.com"
chmod 600 example.com.key

This writes two files: example.com.key, the private key, and example.com.csr, the request. On AlmaLinux and Rocky Linux, /etc/pki/tls/private is the usual folder. The commands below run in the same root shell; type exit when you are done. -noenc leaves the key without a passphrase so the web server can start unattended; it exists from OpenSSL 3.0, and the older spelling -nodes is deprecated.

The Subject Fields

FieldMeaning
CNMain domain name
OLegal name of the organization
LCity
STState or province, in full
CTwo-letter country code

For a domain-validated certificate the authority uses only the names and ignores most of the subject. Organization-validated and extended-validation certificates must match your company records exactly. CA/Browser Forum rules no longer allow the organizational unit field in public TLS certificates, so leave out OU.

Include subjectAltName

Browsers check the name in the address bar against the subjectAltName list, not the common name. Put every name in it, including the one in CN. A missing www name is the classic cause of NET::ERR_CERT_COMMON_NAME_INVALID. Most authorities copy the list from the CSR, and many also let you enter names in the order form.

Use a Config File for Repeat Requests

A small file makes the request repeatable. Save it as example.com.cnf:

[req]
prompt = no
distinguished_name = dn
req_extensions = req_ext

[dn]
CN = example.com
O = Example Inc

[req_ext]
subjectAltName = DNS:example.com, DNS:www.example.com
openssl req -new -newkey rsa:2048 -noenc \
  -keyout example.com.key -out example.com.csr -config example.com.cnf

To renew with the same key, use -key example.com.key in place of -newkey rsa:2048 -noenc -keyout example.com.key. A new key at each renewal is the safer habit.

Check the CSR Before You Submit It

openssl req -in example.com.csr -noout -text -verify

Look for three things: a line saying the self-signature verified, the subject you intended, and a section named Requested Extensions with your alternative names. If the names are missing, the authority may issue a certificate for the common name only.

To confirm that a CSR belongs to a key, compare the public key hashes; the two lines must be identical:

openssl pkey -in example.com.key -pubout | sha256sum
openssl req -in example.com.csr -noout -pubkey | sha256sum

The same check works for the issued certificate with openssl x509 -in example.com.crt -noout -pubkey | sha256sum.

Key Type and Size

  • RSA 2048: the minimum the CA/Browser Forum rules allow for public certificates, and supported by every client.
  • RSA 3072 or 4096: stronger, with slower handshakes.
  • ECDSA P-256: smaller and faster; use -newkey ec -pkeyopt ec_paramgen_curve:prime256v1.

Keep the Key on the Server

The CSR is public: paste it into the order form or send it to whoever orders the certificate. The private key is not. Keep it at mode 600, owned by root, and never paste it into a chat, a support ticket, an e-mail, or a repository. An authority or reseller never needs it. If the key has been exposed, generate a new key and CSR, have the certificate reissued, and ask the authority to revoke the old one.

Install the Issued Certificate

The authority returns your certificate and one or more intermediate certificates. Nginx expects them in one file, your certificate first:

cat example.com.crt intermediate.crt > example.com.fullchain.crt

Point ssl_certificate at the combined file and ssl_certificate_key at the key, then test with sudo nginx -t and reload. Check the result with openssl s_client. For a site that does not need an organization-validated or extended-validation certificate, Let's Encrypt with Certbot handles key, CSR, and renewal for you, as in Certbot with Nginx.

Was this answer helpful?
Loading...