How to Generate a Key and Certificate Request Using OpenSSL
If you want to start up a web server or perhaps just want to add SSL capabilities to a pre-existing website, this quick tutorial may be useful to you.
In a Unix environment, generating a key and certificate request or .key and .csr with OpenSSL is actually quite simple and stress-free. OpenSSL is a cryptographic toolkit that uses the SSL and TLS protocols, so this is what we will be using.
Note: This tutorial was made using Ubuntu Server.
sudo apt-get install openssl
Head back to your terminal and type in the following (change the bold parts to match your details):
openssl req -new -newkey rsa:2048 -nodes -out your_csr_name.csr -keyout your_key_name.key -subj "/C=your_Country/ST=your_state_or_province/L=your_locality_or_city/O=your_organization/OU=your_organizational_unit/CN=your_common_name"
Let's say your website is website.com, you live in Orlando, Florida, and work in IT at Disney. Let's say you also want your CSR name to be myCSR and your key name to be JohnsNewKey. You would put:
openssl req -new -newkey rsa:2048 -nodes -out myCSR.csr -keyout JohnsNewKey.key -subj "/C=USA/ST=Florida/L=Orlando/O=Disney/OU=IT/CN=website.com"
Here's the nitty-gritty of what each part of the above commands means:
In a Unix environment, generating a key and certificate request or .key and .csr with OpenSSL is actually quite simple and stress-free. OpenSSL is a cryptographic toolkit that uses the SSL and TLS protocols, so this is what we will be using.
Note: This tutorial was made using Ubuntu Server.
Installing OpenSSL
If you do not already have OpenSSL, you can quickly install it with:sudo apt-get install openssl
Did you know OpenSSL originated from a project called SSLeay which was developed in 1995?
Generating a Key and Certificate Request
With that out of the way, let's move on to making the key and Certificate Signing Request (or CSR for short.) This can all be done with one command. It's a doozy, but I'll explain each part of the command so you'll know what to use each bit for in the future.Head back to your terminal and type in the following (change the bold parts to match your details):
openssl req -new -newkey rsa:2048 -nodes -out your_csr_name.csr -keyout your_key_name.key -subj "/C=your_Country/ST=your_state_or_province/L=your_locality_or_city/O=your_organization/OU=your_organizational_unit/CN=your_common_name"
openssl req -new -newkey rsa:2048 -nodes -out myCSR.csr -keyout JohnsNewKey.key -subj "/C=USA/ST=Florida/L=Orlando/O=Disney/OU=IT/CN=website.com"
Here's the nitty-gritty of what each part of the above commands means:
- req - This is the certificate request and certificate-generating utility
- -new - This flag will cause a new certificate request to be generated from the request utility. In most cases, this will cause a prompt asking you to fill in some values, but it won't do that this time around.
- -newkey - Still utilizing the request utility, this will cause a new private key to be generated.
- -nodes - Here we're telling the request utility that if a private key is created, do not encrypt it.
- -subj - This will set the subject name for your request. This is why the "-new" flag above won't prompt you for values.
- rsa:2048 - This is for our key. Here we're specifying that we want an RSA key with a size of 2048 bits.

Comments
Post a Comment