How to generate CSR through terminal using OpenSSL
Last Updated: April 04, 2024
Secure Socket Layer (SSL) certificates play a crucial role in securing data transmission over the internet. Whether you're setting up a website, an application, or a server, having an SSL certificate ensures encrypted communication between the client and the server, safeguarding sensitive information from unauthorized access. While there are various methods and tools available to generate SSL certificates, using the terminal provides a straightforward and efficient approach. In this guide, we'll walk through the process of generating SSL certificates using the terminal on a Unix-based system.
- Open a terminal window and enter the following command:
openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
Note: This command creates a private key file named server.key and a CSR named server.csr. You can change these in the command to your domain name, or a preferred file name.
-
You will be prompted for the following information:
-
Country Name: type the two-letter country code for your location, and then press Enter.
-
State or Province Name: type the full name of your State or Province, and then press Enter.
-
Locality Name: type the town or city name for your location, and then press Enter
-
Organization Name: type your company or organization name, and then press Enter.
-
Organizational Unit Name: if needed, type the organizational unit, then press Enter. Alternatively, to leave this field blank, just press Enter.
-
Common Name: type the domain name that you want to secure with the SSL certificate, and then press Enter. Note: The common name is often simply your domain name, such as example.com. Or, if you are going to install an SSL certificate for a subdomain, subdomain.example.com. However, if you are going to install a wildcard certificate, make sure that you use *.example.com, where example.com represents your domain name.
-
Email Address: type the e-mail address that you want to associate with the certificate, and then press Enter.
-
Challenge password: *optional* press Enter.
-
- OpenSSL generates the private key and CSR files based on the .key and .csr filenames used in the command during step 1. These files will be saved to your device, however, you can view and verify the information contained in the CSR through terminal. To do this, type the following command:
cat server.csr
Note: If you changed the .csr file name, you would replace "server" with your chosen name. - You can use the generated CSR to issue your SSL through your name.com account.