How To Create Self-Signed Certificates Using OpenSSL (2024)

In this guide, we have given step-by-step guides on how to create self-signed certificates using the OpenSSL utility. You can create self-signed certificates using commands or automate them using a shell script by following this guide.

Opensslis a handy utility to create self-signed certificates. You can use OpenSSL on all the operating systems such asWindows, MAC, and Linux flavors.

What is a Self Signed Certificate?

A self-signed certificate is an SSL/TSL certificate not signed by a public or private certificate authority. Instead, it is signed by the creator’s own personal or root CA certificate.

Here is what we do to request paid SSL/TLS certificate from a well-known Certificate Authority like Verisign or comodo.

  1. Create acertificate signing request (CSR) with a private key. A CSR contains details about location, organization, and FQDN (Fully Qualified Domain Name).
  2. Send the CSR to the trusted CA authority.
  3. The CA authority will send you the SSL certificate signed by their root certificate authority and private key.
  4. You can then validate and use the SSL certificate with your applications.

But for a self-signed certificate, here is what we do.

  1. Create our own root CA certificate & CA private key (We act as a CA on our own)
  2. Create a server private key to generate CSR
  3. Create an SSL certificate with CSR using our root CA and CA private key.
  4. Install the CA certificate in the browser or Operating system to avoid security warnings.

Need For Our Own Certificate Authority

Most browsers & operating systems hold a copy of root CA certificates of all the trusted certified Certificated Authorities. That’s the reason the browsers won’t show any security messages when you visit standard websites that use SSL from a trusted and well-known commercial Certificate authority.

The following image shows the root CA present in the Firefox browser by default.

At the same time, if you use a self-signed certificate, your browser will throw a security warning. The reason is browsers only trust SSL from a trusted Certificate authority. For example,

Your connection is not privateAttackers might be trying to steal your information from demo.apps.mlopshub.com (for example, passwords, messages or credit cards)

But you can force browsers & operating systems to accept our own certificate authority. So you won’t see the security warning once you install the CA certificate and add it to the trusted list. You can also share the CA certificate with your development team to install in their browsers as well.

Also, you can use this CA to create more than one SSL certificate.

Create Certificate Authority

As discussed earlier, we need to create our own root CA certificate for browsers to trust the self-signed certificate. So let’s create the root CA certificate first.

Let’s create a directory named openssl to save all the generated keys & certificates.

mkdir openssl && cd openssl

Execute the following openssl command to create the rootCA.keyand rootCA.crt. Replace demo.mlopshub.com with your domain name or IP address.

openssl req -x509 \ -sha256 -days 356 \ -nodes \ -newkey rsa:2048 \ -subj "/CN=demo.mlopshub.com/C=US/L=San Fransisco" \ -keyout rootCA.key -out rootCA.crt 

We will use the rootCA.keyand rootCA.crt to sign the SSL certificate.

Note: If you get the following error, commentRANDFILE = $ENV::HOME/.rndline in/etc/ssl/openssl.cnf

Can't load /home/vagrant/.rnd into RNG

Create Self-Signed Certificates using OpenSSL

Follow the steps given below to create the self-signed certificates. We will sign out certificates using our own root CA created in the previous step.

1. Create the Server Private Key

openssl genrsa -out server.key 2048

2. Create Certificate Signing Request Configuration

We will create a csr.conf file to have all the information to generate the CSR. Replace demo.mlopshub.com with your domain name or IP address.

cat > csr.conf <<EOF[ req ]default_bits = 2048prompt = nodefault_md = sha256req_extensions = req_extdistinguished_name = dn[ dn ]C = USST = CaliforniaL = San FransiscoO = MLopsHubOU = MlopsHub DevCN = demo.mlopshub.com[ req_ext ]subjectAltName = @alt_names[ alt_names ]DNS.1 = demo.mlopshub.comDNS.2 = www.demo.mlopshub.comIP.1 = 192.168.1.5IP.2 = 192.168.1.6EOF

3. Generate Certificate Signing Request (CSR) Using Server Private Key

Now we will generate server.csr using the following command.

openssl req -new -key server.key -out server.csr -config csr.conf

Now our folder should have three files. csr.conf, server.csr and server.key

4. Create a external file

Execute the following to create cert.conf for the SSL certificate. Replace demo.mlopshub.com with your domain name or IP address.

cat > cert.conf <<EOFauthorityKeyIdentifier=keyid,issuerbasicConstraints=CA:FALSEkeyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEnciphermentsubjectAltName = @alt_names[alt_names]DNS.1 = demo.mlopshub.comEOF

5. Generate SSL certificate With self signed CA

Now, execute the following command to generate the SSL certificate that is signed by the rootCA.crt and rootCA.key created as part of our own Certificate Authority.

openssl x509 -req \ -in server.csr \ -CA rootCA.crt -CAkey rootCA.key \ -CAcreateserial -out server.crt \ -days 365 \ -sha256 -extfile cert.conf

The above command will generate server.crt that will be used with our server.key to enable SSL in applications.

For example, the following config shows the Nginx config using the server certificate and private key used for SSL configuration.

server {listen 443;ssl on;ssl_certificate /etc/ssl/server.crt;ssl_certificate_key /etc/ssl/server.key;server_name your.domain.com;access_log /var/log/nginx/nginx.vhost.access.log;error_log /var/log/nginx/nginx.vhost.error.log;location / {root /home/www/public_html/your.domain.com/public/;index index.html;}}

Install Certificate Authority In Your Browser/OS

You need to install the rootCA.crt in your browser or operating system to avoid the security message that shows up in the browser when using self-signed certificates.

Installing self-signed CA certificates differs in Operating systems. For example, in MAC, you can add the certificate by double-clicking it and adding it to the keychain. Check the respective Operating system guide on installing the certificate.

  1. For MAC check this guide
  2. Adding certificate to chrome on Windows

Shell Script To Create Self-Signed Certificate

If you want to create self-signed certificates quite often, you can make use of the following shell script. You just need to execute the script with the domain name or IP that you want to add to the certificate.

Save the following shell script as ssl.sh

#! /bin/bashif [ "$#" -ne 1 ]then echo "Error: No domain name argument provided" echo "Usage: Provide a domain name as an argument" exit 1fiDOMAIN=$1# Create root CA & Private keyopenssl req -x509 \ -sha256 -days 356 \ -nodes \ -newkey rsa:2048 \ -subj "/CN=${DOMAIN}/C=US/L=San Fransisco" \ -keyout rootCA.key -out rootCA.crt # Generate Private key openssl genrsa -out ${DOMAIN}.key 2048# Create csf confcat > csr.conf <<EOF[ req ]default_bits = 2048prompt = nodefault_md = sha256req_extensions = req_extdistinguished_name = dn[ dn ]C = USST = CaliforniaL = San FransiscoO = MLopsHubOU = MlopsHub DevCN = ${DOMAIN}[ req_ext ]subjectAltName = @alt_names[ alt_names ]DNS.1 = ${DOMAIN}DNS.2 = www.${DOMAIN}IP.1 = 192.168.1.5 IP.2 = 192.168.1.6EOF# create CSR request using private keyopenssl req -new -key ${DOMAIN}.key -out ${DOMAIN}.csr -config csr.conf# Create a external config file for the certificatecat > cert.conf <<EOFauthorityKeyIdentifier=keyid,issuerbasicConstraints=CA:FALSEkeyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEnciphermentsubjectAltName = @alt_names[alt_names]DNS.1 = ${DOMAIN}EOF# Create SSl with self signed CAopenssl x509 -req \ -in ${DOMAIN}.csr \ -CA rootCA.crt -CAkey rootCA.key \ -CAcreateserial -out ${DOMAIN}.crt \ -days 365 \ -sha256 -extfile cert.conf

Set the script executable permission by executing the following command.

chmod +x ssl.sh

Execute the script with the domain name or IP. For example,

./ssl.sh demo.mlopshub.com

The script will create all the certificates and keys we created using the individual commands. The SSL certificate and private keys get named with the domain name you pass as the script argument. For example, demo.mlopshub.com.key & demo.mlopshub.com.crt

What are the benefits of using a self-signed certificate?

There are several benefits of using a self-signed certificate:

  1. You don’t need to rely on a third party to sign your certificate.
  2. You can create and use your own certificate authority.
  3. You don’t have to pay for a certificate from a CA.
  4. You have more control over your certificates.

What are the drawbacks of using a self-signed certificate?

There are also several drawbacks of using a self-signed certificate:

  1. Your users will need to install the certificate in their browsers or applications.
  2. Your users will need to trust your certificate authority manually.
  3. They unsafe for public facing applications.
  4. None of the browsers or operating systems trust the self-signed certificates unless the user installs them.
  5. Prone to man-in-the-middle attacks.

In general, self-signed certificates are a good option for applications in which you need to prove your own identity. They’re also a good option for development and testing environments. However, they shouldn’t be used for production applications.

Self-Signed Certificates in Organizations

Many organizations use self-signed certificated for their internal applications that are not internet-facing. These certificates are generated using the organization’s internal PKI infrastructure.

DevOps teams and developers can request SSL certificates from the PKI infrastructure to be used in applications.

Self-Signed Certificate FAQ’s

How to create self-signed certificated on Windows?

You can createa self-signedcertificateon windows using Openssl. The OpenSSL commands are the same for all operating systems. You can follow this guide to create a self-signedcertificateon windows using this guide.

How do I get a self-signed certificate?

Self-signed certificate can be generated by you using tools like openSSL or CDSSL PKI toolkit.

Conclusion

In this guide, we have learned how to create self-signed SSL certificates using OpenSSL.

For production use cases, if you don’t want to spend money on SSL certificates, you can try out Letsencrypt.

Hope this self-signed SSL guide was helpful with the script to automate the certificate generation. Do let us know if you face any issues.

Also, SSL/TLS is one of the important topics in DevOps. You can check out the how to become a devops engineer blog to know more.

How To Create Self-Signed Certificates Using OpenSSL (2024)
Top Articles
18 Apprenticeship Interview Questions | Digital Native
NFC Technology
Devotion Showtimes Near Xscape Theatres Blankenbaker 16
Instructional Resources
Aces Fmc Charting
Gunshots, panic and then fury - BBC correspondent's account of Trump shooting
Big Y Digital Coupon App
Tlc Africa Deaths 2021
Bill Devane Obituary
104 Presidential Ct Lafayette La 70503
Craigslist Dog Kennels For Sale
World History Kazwire
2016 Hyundai Sonata Price, Value, Depreciation & Reviews | Kelley Blue Book
Breakroom Bw
ᐅ Bosch Aero Twin A 863 S Scheibenwischer
Virginia New Year's Millionaire Raffle 2022
Craigslistjaxfl
Unity - Manual: Scene view navigation
Teacup Yorkie For Sale Up To $400 In South Carolina
Lola Bunny R34 Gif
Noaa Duluth Mn
Woodmont Place At Palmer Resident Portal
South Bend Weather Underground
2021 MTV Video Music Awards: See the Complete List of Nominees - E! Online
Nk 1399
Villano Antillano Desnuda
The Collective - Upscale Downtown Milwaukee Hair Salon
Tottenham Blog Aggregator
"Pure Onyx" by xxoom from Patreon | Kemono
Memberweb Bw
What Is Xfinity and How Is It Different from Comcast?
Morlan Chevrolet Sikeston
Compress PDF - quick, online, free
Log in or sign up to view
Dadeclerk
Pensacola Cars Craigslist
Ashoke K Maitra. Adviser to CMD&#39;s. Received Lifetime Achievement Award in HRD on LinkedIn: #hr #hrd #coaching #mentoring #career #jobs #mba #mbafreshers #sales…
Indio Mall Eye Doctor
Why I’m Joining Flipboard
About My Father Showtimes Near Amc Rockford 16
Craigs List Hartford
Pokemon Reborn Gyms
No Boundaries Pants For Men
Ups Authorized Shipping Provider Price Photos
Bank Of America Appointments Near Me
Yosemite Sam Hood Ornament
Myapps Tesla Ultipro Sign In
Is Chanel West Coast Pregnant Due Date
Sml Wikia
Palmyra Authentic Mediterranean Cuisine مطعم أبو سمرة
Varsity Competition Results 2022
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 5998

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.