Key and request in one command

openssl req -new -newkey rsa:2048 -noenc -keyout mail.key -out mail.csr -subj "/CN=mail.yourdomain.com" -addext "subjectAltName=DNS:mail.yourdomain.com,DNS:smtp.yourdomain.com"
  • -newkey rsa:2048 creates a new 2048-bit RSA key — the most common size and sufficient for mail servers. rsa:3072 or rsa:4096 work too but cost computation on every handshake.
  • -noenc writes the key without a passphrase, the way a mail server needs it (-nodes with OpenSSL before version 3). Background under Remove a key passphrase.
  • -addext "subjectAltName=…" is the decisive part: clients check the name in the SAN, not the CN. A CSR without SAN leads many CAs to issue a certificate carrying only the CN — or to reject it.

With umask 077 in front, mail.key is created with the right permissions straight away.

Which names belong in it?

Every name the server is addressed by:

  • the MX hostname from the MX record — for inbound mail,
  • the name for submission and retrieval if it differs (smtp., imap.),
  • with several MX hosts sharing one certificate: all of them.

The mail domain alone (yourdomain.com) is not enough when the MX is mail.yourdomain.com — see Set up the MX certificate.

EC instead of RSA

openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 -noenc -keyout mail.key -out mail.csr -subj "/CN=mail.yourdomain.com" -addext "subjectAltName=DNS:mail.yourdomain.com"

A P-256 key is as strong as 3072-bit RSA and considerably faster in the handshake. All current mail servers handle it. If you must serve very old peers too, stay with RSA — or run both side by side (Postfix: smtpd_tls_chain_files with two pairs).

For an existing key

On a renewal with the same key — say because a DANE record with selector 1 points at it — the key stays and only the request is new:

openssl req -new -key mail.key -out mail.csr -subj "/CN=mail.yourdomain.com" -addext "subjectAltName=DNS:mail.yourdomain.com"

How that interacts with the DANE record is covered in Set up DANE.

Checking the request before submitting

openssl req -in mail.csr -noout -verify openssl req -in mail.csr -noout -text | grep -A1 "Subject Alternative Name"

The first line reports Certificate request self-signature verify OK, the second shows the names entered. If one is missing, now is the moment to recreate the request — not after issuance.

Once the certificate comes back, Check certificate and key verifies that it matches the key and the chain is complete. If you need to serve Windows, build a PFX file from it.

Verify your work

A test mail through your mail server to hello@analyzemy.email shows how it looks from outside: TLS path, SPF, DKIM, DMARC and blacklists in one report.

Analyze your email now

Last updated: · All guides