CSR and Private Key Generation Using OpenSSL
-
You can generate a Certificate Signing Request (CSR) and a Private Key using OpenSSL on almost any server or operating system. The same process applies to Apache, Node.js, Nginx, and other environments that support OpenSSL.
You will need terminal access to the server or computer and permission to create files in the working directory.
- Automatic renewals
- Less manual work
-
-
*
Step 1. Check OpenSSL Installation
Open your terminal or connect to your server via SSH. Run the following command:
openssl versionIf OpenSSL is installed, the command will display its version.
If it is not available, install OpenSSL using your operating system's package manager. OpenSSL is a separate command-line utility and does not need to be installed through npm.
-
*
Step 2. Generate a Private Key and CSR
Run the following command:
RSA keys:
openssl req -new -newkey rsa:2048 -noenc -keyout example.com.key -out example.com.csrECC keys:
openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -noenc -keyout example.com.key -out example.com.csrNote: Replace example.com with your domain name.
This command generates two files:
- example.com.key — your private key.
- example.com.csr — your Certificate Signing Request.
Note: If you are using an older OpenSSL version that does not recognize -noenc, replace it with -nodes.
-
*
Step 3. Enter the Required Information
OpenSSL will prompt you to enter the following details:
Field Description Country Name Your two-letter country code (e.g., US). State or Province Name Your state or province. Locality Name Your city. Organization Name Your organization's legal name, if applicable. Organizational Unit Name Your department, if applicable. Common Name The fully qualified domain name (FQDN) you want to secure, e.g., www.example.com. Email Address A contact email address, if requested. For a Wildcard certificate, enter a name such as *.example.com in the Common Name field.
When prompted for the following additional attributes, leave them blank:
- A challenge password: Do not enter a password.
- An optional company name: Leave blank unless specifically required.
-
*
Step 4. Copy and Submit Your CSR
After completing the prompts, OpenSSL will save both files in your current directory.
To display the CSR, run:
cat example.com.csrCopy the entire CSR, including the header and footer:
-----BEGIN CERTIFICATE REQUEST----- Your encoded CSR data -----END CERTIFICATE REQUEST-----Paste it into the CSR field during your SSL certificate order.
Important: Keep the Private Key (.key file) secure and do not send it to the Certificate Authority. The -noenc (or -nodes) option creates an unencrypted private key, so make sure access to the file is properly restricted.
-