Follow
Ubuntu Linux

How to Create a Self-Signed SSL Certificate on Ubuntu 24.04

Richard
Written by
Richard
Feb 21, 2025 Updated Mar 20, 2026 3 min read
How to Create a Self-Signed SSL Certificate on Ubuntu 24.04
How to Create a Self-Signed SSL Certificate on Ubuntu 24.04

You create a self-signed SSL certificate on Ubuntu 24.04 by generating your own private key and public certificate using OpenSSL.

A self-signed certificate is a digital certificate you create and sign yourself, meaning it’s not verified by a trusted Certificate Authority (CA). This is perfect for testing and development where you need to secure local web servers or applications without paying for a commercial certificate.

Using OpenSSL, you can easily generate a certificate valid for a specific period, like 365 days, using straightforward commands such as `openssl genrsa` and `openssl req`. This process provides you with a fundamental understanding of SSL/TLS encryption.

⚡ Quick Answer

Generate a private key and certificate signing request using `openssl genrsa` and `openssl req`. Then, create the self-signed certificate with `openssl x509`, specifying the key, request, and desired validity period.

OpenSSL config file

An easy way to manage your server hostname is in the OpenSSL config file containing all the server names.

In this post, we’ll add all the DNS or domain names for which we want to generate certificates.

First, open the openssl.cnf file in the [/etc] directory by running the command below.

🐧Bash / Shell
sudo nano /etc/ssl/openssl.cnf

Then, add a [ Domain Name ] section containing domain and sub-domains. If you have multiple hostnames or domain names, comma-separate them.

Add your your entry to the end of the file.

💻Code
[ example.com ]
subjectAltName = DNS:srv1.example.com, DNS:srv2.example.com, DNS: srv3.example.com

Save the file and exit.

Create SSL certificate

With your hostnames or domain names specified, create your self-signed SSL certificates.

🐧Bash / Shell
sudo openssl ecparam -name prime256v1 -genkey -out server.key
sudo openssl req -new -key server.key -out server.csr

When prompted, enter the certificate details in the server.csr file. We’ll use this file to generate the actual certificate.

💻Code
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]:New York
Locality Name (eg, city) []:Brooklyn
Organization Name (eg, company) [Internet Widgits Pty Ltd]:GeekRewind
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:srv1.example.com
Email Address []:admin@example.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

Finally, run the command below to generate a self-signed certificate valid for 10 years.

🐧Bash / Shell
sudo openssl x509 -in server.csr -out server.crt -req -signkey server.key -extfile /etc/ssl/openssl.cnf -extensions example.com -days 3650

If the command runs successfully, you will see a result similar to the lines below.

💻Code
Certificate request self-signature ok
subject=C = US, ST = New York, L = Brooklyn, O = GeekRewind, OU = IT, CN = srv1.example.com

Once the certificates are generated, you can copy them to the [/etc/ssl/private] directory.

🐧Bash / Shell
sudo cp server.* /etc/ssl/private

You should see the files created when you list the content of your /etc/ssl/private directory.

💻Code
total 24
drwx--x--- 2 root ssl-cert 4096 Feb 21 10:05 .
drwxr-xr-x 4 root root 4096 Feb 21 10:01 ..
-rw-r--r-- 1 root root 847 Feb 21 10:05 server.crt
-rw-r--r-- 1 root root 481 Feb 21 10:05 server.csr
-rw------- 1 root root 302 Feb 21 10:05 server.key
-rw-r----- 1 root ssl-cert 1700 Jan 15 12:06 ssl-cert-snakeoil.key

Validate the server.crt file using this link.

Self signed certificate
Self signed certificate

That should do it!

Conclusion:

Creating a self-signed SSL certificate on Ubuntu 24.04 is a straightforward process that can significantly enhance your understanding of SSL/TLS. Here are the key takeaways:

  • No Cost Involved: Self-signed certificates are free to create, making them an economical choice for personal projects.
  • Hands-on Experience: This process provides practical knowledge about how digital certificates work.
  • Customizable Options: You can easily specify multiple hostnames or domain names in the OpenSSL configuration file.
  • Longevity: The generated self-signed certificate can be valid for a substantial period (up to 10 years).
  • Easy Management: Storing the certificate files in the appropriate directories simplifies management and accessibility.

Following these steps, you can successfully generate a self-signed SSL certificate tailored to your needs.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Create a Self-Signed SSL Certificate for MariaDB on Ubuntu 24.04
Ubuntu Linux How to Create a Self-Signed SSL Certificate for MariaDB on Ubuntu 24.04
Secure MySQL with Self-Signed SSL Certificate on Ubuntu 24.04
Ubuntu Linux Secure MySQL with Self-Signed SSL Certificate on Ubuntu 24.04
How to Install WebStorm on Ubuntu 24.04
Ubuntu Linux How to Install WebStorm on Ubuntu 24.04
How to Install Syncthing on Ubuntu 24.04
Ubuntu Linux How to Install Syncthing on Ubuntu 24.04

4 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *