SSL, Apache2 and Ubuntu Gutsy 7.10

In earlier versions of Ubuntu there are some simple to use scripts to enable apache2 for https acess with a self signed/generated certificate/key. However in Gutsy these scripts are not present and you are left to fend for your self. So here it goes…

First we need to enable the SSL module:

sudo a2enmod ssl

Now we need to change to the root user because the following folder is restricted from normal users, plus this will allow us to see our work:

sudo -s -H

Enter your root password. Now we need to enter the following directory:

cd /etc/ssl/private

At this point we can generate the self-signed public and private certificate:

openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout -out

You will be prompted to answer a number of questions regarding your site’s name and location.

If you have not already done so, go ahead and leave the root user mode, simply type exit at the command prompt. Lastly we need to create a new port 443 site for apache2 and set the old site to use only port 80.

cd /etc/apache2/sites-available
sudo sed -i ‘1,2s/\*/*:80/’ default
sudo cp default ssl
sudo sed -i ‘1,2s/\*:80/*:443/’ ssl
sudo sed -i “3a\\\tSSLEngine On\n\tSSLCertificateFile
/etc/ssl/private/” ssl
sudo a2ensite ssl

What this did was take the default site and have it only operate on port 80. It also took your default site and made a copy of it and enabled it for port 443 use. The new port 443 site has been configured to use your newly generated certificate file. Lastly, the new ssl site has been enabled.

Lets move ahead and restart apache:

sudo /etc/init.d/apache2 force-reload

Finally give the site a browse: https://localhost

Leave a Reply

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