How to Generate a CSR (Certificate Signing Request) in Linux?


Introduction

In today's digital age, website security has become an extremely important aspect for businesses to consider. Cybercrime is on the rise and attackers are constantly finding new ways to exploit vulnerabilities in online systems. One of the main ways to protect websites from cyber threats is by implementing SSL/TLS certificates, which help encrypt data transmitted between a user's browser and a web server.

A Certificate Signing Request (CSR) is an essential component of obtaining an SSL/TLS certificate. It contains information about the domain name and organization requesting the certificate, as well as other details required for verification purposes.

Overview of Generating a CSR in Linux

Generating a CSR in Linux can be done through various methods such as using OpenSSL command-line tool or GUI tools like Certbot or Acme.sh among others. Each method requires specific steps that need to be followed carefully in order to obtain a valid CSR. The process typically involves generating a private key, which is used for encrypting data sent between the web server and browser, creating a Certificate Signing Request (CSR), which includes information about the website owner and domain name among other details required by CAs for validation purposes.

submitting your request file containing your csr code to your favorite CA providers like ComodoSSL.com or DigiCert.com who will validate your submission request before issuing you with an SSL/TLS certificate. In this article we will focus on generating CSRs using OpenSSL command-line tool in Linux.

Preparing to Generate a CSR in Linux

Prerequisites for generating a CSR

Before generating a CSR in Linux, there are some prerequisites that must be met. The first and foremost requirement is having root access to the server.

This enables you to have the necessary privileges to modify critical system files and run commands with administrative rights. Additionally, you need to have installed OpenSSL on your system.

Checking if OpenSSL is installed on your system

To check if OpenSSL is already installed on your system, you can use the command-line interface (CLI) or GUI tools such as Synaptic Package Manager or Ubuntu Software Center. To check using CLI, run the following command −

openssl version 

This will display the version of OpenSSL installed on your system. If it returns an error that openssl command not found, then it means OpenSSL is not installed.

Alternatively, you can use the package manager specific to your distribution (e.g., APT for Ubuntu) by running −

sudo apt-get install openssl 

This installs OpenSSL along with its dependencies. Once installed, you can verify that it has been properly installed by checking its version again using `openssl version`.

Before generating a CSR in Linux, ensure that you have root access and have installed OpenSSL on your system following the steps above. It's crucial to meet these requirements because without them, generating a CSR won't be successful and can significantly impact website security.

Generating a CSR using OpenSSL command-line tool

Generating a Certificate Signing Request (CSR) is a crucial step in the process of obtaining an SSL/TLS certificate for your website. One of the most commonly used tools to generate a CSR in Linux is the OpenSSL command-line tool. This tool enables you to create a new private key and CSR, both using one simple command.

Step-by-step instructions

To generate a CSR using OpenSSL, follow these steps −

  • Open your terminal window and run the following command −

openssl req -new -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr

This command creates a new private key with 2048-bit encryption and generates a new CSR at the same time.

  • You will be prompted to enter some information about your organization, such as country code, state/province, city/locality, organization name, and common name (domain name). You can leave some fields blank by pressing enter if you do not want to provide certain information.

You are about to be asked to enter information that will be incorporated into your certificate request. 

What you are about to enter is what is called a Distinguished Name or a DN. 
There are quite a few fields but you can leave some blank For some fields there will be a default value, 
If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US 
State or Province Name (full name) [Some-State]:California Locality Name (eg, city) []:San Francisco 
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Example Company Ltd. Organizational Unit Name (eg, section) []: 
Common Name (e.g. server FQDN or YOUR name) []:example.com Email Address []:
  • After providing all the required information, the tool will generate two files in your current directory − "example.com.key" and "example.com.csr". The former is your private key, and the latter is your CSR.

Explaining each option used in the command

Now let's take a closer look at each option used in the OpenSSL command: - req: This tells OpenSSL to create a new CSR.

  • new − This tells OpenSSL that we want to generate a new CSR instead of using an existing one.

  • newkey rsa:2048 − This tells OpenSSL to create a new RSA private key with 2048-bit encryption.

  • nodes − This tells OpenSSL not to encrypt the private key. In other words, it creates an unencrypted (clear text) private key.

  • keyout example.com.key − This specifies where you want to save your private key. Replace "example.com" with your actual domain name.

  • out example.com.csr − This specifies where you want to save your CSR. Again, replace "example.com" with your actual domain name.

Common mistakes to avoid

Here are some common mistakes that you should avoid when generating a CSR using OpenSSL −

  • Mistyping information about your organization can lead to errors when applying for an SSL/TLS certificate later on. Make sure you enter all required fields accurately and double-check before submitting.

  • Forgetting to include or mistyping an email address can lead to delays in receiving important notifications about your SSL/TLS certificate application status or expiration date.

  • Using weak encryption for your private key (less than 2048 bits) can compromise the security of your website and allow hackers to steal sensitive data from users.

    Always use strong encryption for maximum security.

Generating a CSR using GUI tools (optional)

Though generating a CSR through the command line is the most common method, some users may find it more convenient to use graphical user interface (GUI) tools. There are various GUI tools available that can be used for generating a CSR in Linux.

Mention some GUI tools that can be used to generate

  • OpenSSL Certificate Manager − This tool is part of the OpenSSL package and provides a graphical interface for managing certificates, including generating CSRs. It is available on most Linux distributions and offers an easy-to-use interface for creating CSRs.

  • XCA −This is an open-source certificate and key management tool that provides support for creating SSL/TLS certificates, including CSRs.

    It offers advanced features such as certificate templates, key backup, revocation support, and more.

  • Keytool IUI −If you're looking for a Java-based tool to generate CSRs in Linux, then Keytool IUI might be your best bet.

It uses the Java Keytool command-line utility under the hood but offers an intuitive graphical user interface with several useful features.

Conclusion

Generating a CSR in Linux is a crucial step towards securing your website with SSL/TLS certificates. While there are various methods to do so, using OpenSSL command-line tool remains the most popular choice due to its simplicity and effectiveness.

If you're new to Linux or not comfortable with the command line interface though, then using one of the above-mentioned GUI tools can help make things easier for you.

Updated on: 06-Jun-2023

143 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements