A SSL certificate is a way to encrypt a site’s information and create a more secure connection. While Certificate authorities can issue SSL certificates that verify the server’s details, a self-signed certificate has no third party corroboration. This tutorial explains how to create a self-signed SSL certificate, add it to your VPS, and configure the SSL file to display the certificate to the world.
If Apache is not already running on your server, these is an Apache httpd package readily available for aptitude under the name apache2.
Run the following command to install:
sudo apt-get install apache2
To test that the package was properly installed, enter your VPS IP address into your browser. If the installation was successful, the browser shall display the following:
It works!
This is the default web page for this server.
The web server software is running but no content
has been added, yet.
We need to configure httpd in order to support SSL. It is available in the httpd installation as a part of the apache2-common package.
Use the following commands to enable SSL:
sudo a2ensite default-ssl
sudo a2enmod ssl
This time, as stated, let’s restart Apache2:
sudo service apache2 restart
To test that the module was properly installed, we are going to type our IP address into the browser as before; however, this time we will use https://. Follow this with your IP address in your browser.
The first time you access the page, the browser will warn you that the certificate of the site is not trusted. You can proceed and you will get to the same page as before:
It works!
This is the default web page for this server.
The web server software is running but no content has been added,
yet.
To use a self-signed certificate, the package ssl-cert must be installed.
I wanted to configure my own self-signed certificate for the server and to store it in /etc/apache2/ssl. To do so, run the following commands:
sudo mkdir /etc/apache2/ssl
When we request a new certificate, we can specify how long the certificate should remain valid by changing the 365 to the number of days we prefer. As it stands this certificate will expire after one year.
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
With this command, we will be both creating the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.
This command will prompt terminal to display a lists of fields that need to be filled in.
The most important line is “Common Name”. Enter your official domain name here or, if you don’t have one yet, your site’s IP address.
<pre>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]:<span class="highlight">US</span>
State or Province Name (full name) [Some-State]:<span class="highlight">New York</span>
Locality Name (eg, city) []:<span class="highlight">NYC</span>
Organization Name (eg, company) [Internet Widgits Pty Ltd]:<span class="highlight">Awesome Inc</span>
Organizational Unit Name (eg, section) []:<span class="highlight">Dept of Merriment</span>
Common Name (e.g. server FQDN or YOUR name) []:<span class="highlight">example.com </span>
Email Address []:<span class="highlight">webmaster@awesomeinc.com</span></pre><br/>
Now we have all of the required components of the finished certificate.The next thing to do is to set up the virtual hosts to display the new certificate.
Open up the SSL config file:
nano /etc/apache2/sites-available/default-ssl
Within the section that begins with <VirtualHost default:443>, quickly make the following changes.
Add a line with your server name right below the Server Admin email:
ServerName example.com:443
Replace example.com with your DNS approved domain name or server IP address (it should be the same as the common name on the certificate).
Find the following three lines, and make sure that they match the extensions below:
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
Save and Exit out of the file.
Before the website that will come on the 443 port can be activated, we need to enable that Virtual Host:
sudo a2ensite default
You are all set. Restarting your Apache server will reload it with all of your changes in place.
sudo service apache2 reload
In your browser, type https://youraddress, and you will be able to see the new certificate.
Once you have setup your SSL certificate on the site, you can <a href=“https://www.digitalocean.com/community/articles/how-to-set-up-vsftpd-on-ubuntu-12-04”>Install an FTP server</a> if you haven’t done so yet.
<div class=“author”>By Adam LaGreca</div>
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
root@cloud:/home/def# gedit /etc/apache2/sites-available/default-ssl
(gedit:3266): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
(gedit:3266): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
(gedit:3266): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files root@cloud:/home/def# sudo a2ensite default ERROR: Site default does not exist! root@cloud:/home/def#
Kamaln7 asked someone for:
sudo ls /etc/apache2/sites-available 000-default.conf default-ssl default-ssl.conf
What is the problem? Can anyone help me?
thank you, everything works!
I have done steps 1 & 2, and checked that I was able to https://localhost. Why do I need to continue with steps 3 & 4 if I’m already able to stablish a secured connection?
@analoguecolour: Are you starting from a fresh server or is this something that you have already set up? Is there something else listening on port 443?
Make sure you enabled the SSL configuration:
<pre> a2ensite default-ssl service apache2 reload </pre>
Are there any errors in “/var/log/apache2/error.log” ?
I get the following error after following this tutorial:
SSL received a record that exceeded the maximum permissible length. (Error code: ssl_error_rx_record_too_long)
@Tural: It is free however it will appear as “untrusted” in all browsers since it’s self-signed and not signed by a trusted CA.
this ssl free? lifetime?
@braddjwinter: What’s the output of <pre>sudo ls /etc/apache2/sites-available</pre>?
i’m getting ‘site default does not exist!’ at the last step!