Generate a certificate signing request
To generate a private key and a CSR together, run `openssl req -new -newkey rsa:2048 -nodes -keyout private.key -out request.csr`. OpenSSL prompts for the subject fields, or you can supply them non-interactively with `-subj "/C=US/ST=California/O=Example Inc/CN=example.com"`. To create a CSR from a key you already have, drop `-newkey` and `-nodes` and use `-key private.key` instead. Add subject alternative names in the same command — a certificate without them fails in every modern browser.
Key and CSR in one command #
openssl req -new -newkey rsa:2048 -nodes -keyout private.key -out request.csr Replace these values
| Placeholder | What to put there |
|---|---|
-new | Create a new request. |
-newkey rsa:2048 | Generate a new 2048-bit RSA key at the same time. |
-nodes | Write that key unencrypted. Required for unattended server startup. |
-keyout private.key | Where the new private key is written. |
-out request.csr | The CSR to send to the certificate authority. |
Non-interactive #
Prompts are fine once and useless in a script. -subj supplies everything up front:
openssl req -new -newkey rsa:2048 -nodes \
-keyout example.com.key -out example.com.csr \
-subj "/C=US/ST=California/L=San Francisco/O=Example Inc/CN=example.com" \
-addext "subjectAltName=DNS:example.com,DNS:www.example.com" From a key you already have #
openssl req -new -key private.key -out request.csr \
-subj "/CN=example.com" \
-addext "subjectAltName=DNS:example.com" Note there is no -nodes here — that flag only affects a key being generated, and passing it with
-key does nothing.
The subject fields #
| Field | Meaning | Checked by the CA? |
|---|---|---|
C |
Two-letter country code | For OV and EV |
ST |
State or province, spelled out | For OV and EV |
L |
Locality or city | For OV and EV |
O |
Organisation, as legally registered | For OV and EV |
OU |
Organisational unit | No — deprecated by the CA/Browser Forum |
CN |
Primary hostname | Yes, but ignored by browsers for matching |
emailAddress |
Contact address | Rarely used, often rejected |
At an interactive prompt, entering a single . leaves a field empty.
EC keys #
openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
-keyout private.key -out request.csr \
-subj "/CN=example.com" \
-addext "subjectAltName=DNS:example.com" Verify before you submit #
Two checks, both cheap, both catching failures that are otherwise invisible until after issuance:
openssl req -in request.csr -noout -verify Expected output
Certificate request self-signature verify OK
openssl req -in request.csr -noout -subject -text | grep -A1 "Subject Alternative Name" Frequently asked questions
- What does -nodes mean?
- It stands for "no DES" and writes the generated private key unencrypted. Web servers need this because they cannot answer a passphrase prompt at boot. OpenSSL 3 added
-noencas a clearer spelling of the same flag. - Which subject fields are required?
- For a domain-validated certificate, effectively only the Common Name, and even that is now ignored for hostname matching. Organisation-validated and extended-validation certificates require the organisation and location fields to match verified records. Leave a field blank by entering a single dot at the prompt.
- Can I create a CSR from a certificate I already have?
- Yes, if you still have the key.
openssl x509 -x509toreq -in certificate.crt -signkey private.key -out request.csrcopies the subject across. Check the SANs came with it, because they often do not. - Does the CA see my private key?
- No. The CSR contains only your public key and a signature proving you hold the private one. Any party asking you to send a private key should be refused.
References
- openssl-req(1) — CSR creation and subject syntax
- RFC 2986: PKCS #10 certification request syntax — the CSR structure itself