Simple steps to generate CSR using openssl with examples

Deepak Prasad


How to generate Certificate Signing Request using openssl in Linux. is it possible to generate CSR with openssl? Can we automate the steps to create Certificate Signing Request instead of interactive prompts? Do we need ssl.conf to generate CSR with openssl?

In this tutorial I will cover these questions and share the steps to generate CSR using openssl in Linux.


Steps involved to configure SSL

You can either create your own CA certificate or you can send request to third party CA for certificates to be used by your application. One of the most common uses of certificates is to have the certificate installed on the web server for SSL, which encrypts traffic between the client and the server.

When configuring SSL on a web site, or applying certificates to any application, there are four major steps:


Create the certificate signing request (CSR)

  • The first step is to create the certificate request, also known as the certificate signing request (CSR).
  • You typically navigate to the web site of the CA to fill out a web form to create the request or create the request from the actual application.
  • For example, Microsoft’s IIS and Exchange Server have wizards to create the certificate request. Once the request is made, it is stored in a text file.
  • We will use openssl to generate CSR which can also be submitted to third party CA or can be used by your own CA certificates


Submit the request

  • Once you have the CSR, you are then ready to submit the request (contents of the CSR) to the CA.
  • For third part CA, you can do this by navigating to the CA’s web site.
  • If you are using your own CA then this can be done using openssl


Download the certificate

  • After submitting the request through the web site for third party CA, you need to download the resulting certificate to your computer.
  • You typically are provided a link at the end of the “submit the request” phase to download the certificate.
  • With openssl at the end of execution you will get your certificates based on the path provided.


Install the certificate

  • Once you have the certificate, you can install it in your application.


List of third party CA

The following are some Certificate Authorities:

All of these companies accept certificate-signing requests generated by the mod_ssl package, for use with Apache with mod_ssl.


What is Certificate Signing Request (CSR)?

  • When you make your server key file and certificate, you also make a certificate-signing request.
  • A certificate authority will use a CSR to create your SSL certificate, but it does not need your private key.
  • The information required for this request must match exactly the Company Name, registered domain name, and other details that are required by the Certificate Authority, in order for them to process your request.
  • The Company Name must match the FQDN of your server or else the certificate will throw name mismatch error or TLS handshake failure
  • CSR also includes many other details related to your organization for which you are requesting the certificates
  • The file is automatically encoded in a special format.



I hope you have an overview of openssl and different terminologies using with certificates. Since I am using a Linux environment, I will use openssl to generate private key and CSR for this tutorial. openssl is installed by default in more Linux distributions. You can verify the same using

# rpm -q openssl

If it is not installed then based on your distribution you can install openssl package. I am using RHEL/CentOS so I will use yum to install opensll. For Ubuntu, Debian you can use apt-get

# yum -y install openssl
Make sure you keep the private key which you will generate with your CSR. Your CSR will work only with this private key.


Generate CSR (Interactive)

In this example I will show the interactive method which means you will be prompted to fill in the required data for CSR.

To generate a Certificate Signing request you would need a private key. Ideally I would use two different commands to generate each one separately but here let me show you single command to generate both private key and CSR

# openssl req -new -newkey rsa:2048 -nodes  -keyout ban27.key -out ban27.csr

In this example we are creating a private key (ban27.key) using RSA algorithm and 2048 bit size. Next we will use this ban27.key to generate our CSR (ban27.csr)

Snippet output from my terminal for this command

generate csr
Generate CSR (Interactive)


  • -newkey: This option creates a new certificate request and a new private key.
  • rsa:2048: Generates RSA key with 2048 bit size
  • -nodes: The private key will be created without any encryption
  • -keyout: This gives the filename to write the newly created private key to
  • -out: This specifies the output filename to write to or standard output by default.

So our key and CSR are created:

# ls -l ban27.*
-rw-r--r-- 1 root root 1078 Aug 10 08:21 ban27.csr
-rw------- 1 root root 1704 Aug 10 08:20 ban27.key


Generate CSR (Non-interactive)

In this example I will share non-interactive method to generate CSR which means you will not be prompted for any input.

Create a configuration file with the content required to generate CSR. I have created a sample file which you can use as template.

# cat server_cert.cnf
distinguished_name = req_distinguished_name
prompt = no
C = IN
ST = Karnataka
L = Bengaluru
O = GoLinuxCloud
OU = R&D
CN =

Next we will use the same command as earlier and add -config server_cert.cnf to make sure you are not prompted for any input.

# openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out ban27.csr -config server_cert.cnf

As expected this command didn't prompt for any input. We can use this for automation purpose. Below is a snippet from my terminal

Generate CSR (Non-Interactive)
Generate CSR (Non-Interactive)


Verify Certificate Signing Request

Now since we have our CSR, we will verify the content of the certificate.

# openssl req -noout -text -in ban27.csr
Certificate Request:
        Version: 1 (0x0)
        Subject: C = IN, ST = Karnataka, L = Bengaluru, O = GoLinuxCloud, OU = R&D, CN =
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Exponent: 65537 (0x10001)
    Signature Algorithm: sha256WithRSAEncryption


What's Next

Now you can either submit this CSR to third party CA to get your certificates or if you want to sign these certificates using your own CA then:



In this tutorial I shared the steps to generate interactive and non-interactive methods to generate CSR using openssl in Linux. Once these CSR are generated, you can share it to your third party CA. To test your server, or to run your server internally in your organization, you can act as your own Certificate Authority and self-sign your certificate.

Lastly I hope the steps from the article to generate CSR on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

Views: 558

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can reach out to him on his LinkedIn profile or join on Facebook page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

Leave a Comment

GoLinuxCloud Logo

We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Programming Languages