Secure Websites Using SSL And Certificates

This how-to will guide you through the entire process of setting up a secure website using SSL and digital certificates. This guide assumes that you have already a fully functional (and configured) server running Apache, BIND, and OpenSSL. Just as a side note, this guide was written based on a Fedora Core 6 distribution, but should be the same for most other distros out there.



Today it is possible to create a secure website with relative ease by requiring a client to present a digitally signed certificate. A digitally signed certificate is simply a piece of information that contains data about the subject, public key, dates of validity, identification of the Certificate Authority (CA), and the digital signature. There are typically two ways to go about creating a secure website. First is by the use of a self-signed certificate. The second way is by using a Trusted Certificate signed by a CA. The choice is up to you, and this tutorial will show you how to do both. Go ahead and su into root and let's begin!


Step 1: Preconfigure OpenSSL

We can preconfigure OpenSSL to fill in the fields of the certificate by modifying its configuration file. Doing this will save us a few steps during the certificate creation process. First, navigate to the SSL directory and do a listing of files

# cd /etc/pki/tls
# ls -al

In the listing you should see the file openssl.cnf. Go ahead and open up this file in your favorite editor and find the beginning of the [ req_distinguished_name ] section. Modify the countryName_default, stateOrProvinceName_default, 0.organizationName_default, 1.organizationName_default values with the values that suit your needs. The section of the file you are looking for looks like this

[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
countryName_default             = US
countryName_min                 = 2
countryName_max                 = 2
stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = Berkshire
localityName                    = Locality Name (eg, city)
localityName_default            = Berkshire Hills
0.organizationName              = Organization Name (eg, company)
0.organizationName_default      = My Secure Website Company
# we can do this but it is not needed normally :-)
#1.organizationName             = Second Organization Name (eg, company)
#1.organizationName_default     = MSWC
organizationalUnitName          = Organizational Unit Name (eg, section)
#organizationalUnitName_default = Your IT Department
commonName                      = Common Name (eg, your name or your server\'s hostname)
commonName_max                  = 64
emailAddress                    = Email Address
emailAddress_max                = 64

Once you have made the changes, save and quit the editor.


Step 2: Creating The Server CA

Now we must create the server's CA. You should still be in the /etc/pki/tls directory, if you are not sure just run a quick pwd to find out. We now need to make sure that we have no other certificates in the system:

# rm -rf ../../CA

Once that is done, we will use the shell scripts OpenSSL comes with to create a new CA:

# misc/CA -newca

A dialog will appear saying:

CA certificate filename (or enter to create)

Go ahead and press enter. At this point the program will begin generating the CA. During this process you will be asked to enter a PEM pass phrase, create one and write it down! Once you have entered the PEM and verified it you will be asked some questions about the Distinguished Name (DN). A lot of the questions will have the correct values in them by default since we edited the openssl.cnf file. So press enter until it asks for the Common Name. When asked for the common name you should put down the server's hostname. It should look like this:

#misc/CA -newca
   CA certificate filename (or enter to create)
   Making CA certificate ...
   Generating a 1024 bit RSA private key
   writing new private key to '../../CA/private/./cakey.pem'
   Enter PEM pass phrase:    XXXXXXXXX
   Verifying - Enter PEM pass phrase:    XXXXXXXXX
  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) [US]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [Berkshire Hills]:
Organization Name (eg, company) [My Secure Website Company]:
Organizational Unit Name (eg, section) [Your IT Department]:
Common Name (eg, your name or your server's hostname) []:hostname
Email Address []

The CA for the server has been created and placed in the /etc/CA/private/cakey.pem file.


Step 3: Creating A Server Certificate Request

Now that we have the CA established, we need to make a request to create the certificate. Once again, using the shell scripts included with OpenSSL we want to run this command:

# misc/CA -newreq

Once the command has been entered, the program will being generating the request. When asked for the PEM, go ahead and enter it and press enter. Once again you will be asked the same questions about the Distinguished Name (DN). Everything should be the same, except this time when asked for the common name you should enter the complete address of the site you wish to secure (not just the hostname as this will cause internet browsers to see a conflict!). Once you have entered the Common Name you will be asked to create a Challenge Password, create one and write it down. This process should look like this:

#misc/CA -newreq
   CA certificate filename (or enter to create)
   Making CA certificate ...
   Generating a 1024 bit RSA private key
   writing new private key to 'newkey.pem'
   Enter PEM pass phrase:    XXXXXXXXX
   Verifying - Enter PEM pass phrase:    XXXXXXXXX
  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) [US]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [Berkshire Hills]:
Organization Name (eg, company) [My Secure Website Company]:
Organizational Unit Name (eg, section) [Your IT Department]:
Common Name (eg, your name or your server's hostname) []
Email Address []
   A challenge password []:
   An optional company name []:
   Request is in newreq.pem, private key is in newkey.pem

The certificate request has now been created and placed in the file /etc/pki/tls/newreq.pem and the private key is in /etc/pki/tls/newkey.pem.


Step 4: Signing The Certificate

Before you move on to the next step you need to consider which of the two routes you are going to take - the self-signed certificate or trusted third-party signed certificate. The choice is entirely up to you. If your website is not for commercial use, you can probably get away with using a self-signed certificate, however, most web browsers will not recognize it as a "trusted website" right away since it does not have the signature of a trusted CA. Alternatively to both the self-signed or purchased methods, I recommend looking into using is a completely public, community driven, and FREE CA that is growing.

If you want to create a Self-Signed certificate go to Step 4A.

If you want to create a Trusted certificate thru a third party go to Step 4B.


Step 4A - The Self Signed Certificate

This is a fairly simple process. Using the shell scripts we can sign our own certificate with ease by running the following command

# misc/CA -sign

Once executed the program loads the configuration file from the openssl.cnf file. Once it opens the CA key information you will be prompted for the PEM pass phrase, go ahead and enter it. Once the pass phrase is entered the program then verifies the integrity and validity of the data. Once it is done checking, it will ask if you want to sign the certificate, enter "y" and continue. The whole result should look something like this:

# misc/CA -sign
   Using configuration from /etc/pki/tls/openssl.cnf
   Enter pass phrase for ../../CA/private/cakey.pem: XXXXXXXXX
   Check that the request matches the signature
   Signature ok
   Certificate Details:
   Serial Number: 1 (0x1)
   Not Before: Dec 22 18:52:38 2006 GMT
   Not After : Dec 22 18:52:38 2007 GMT
   countryName               = US
   stateOrProvinceName       = Berkshire
   localityName              = Berkshire Hills
   organizationName          = My Secure Website Company
   organizationalUnitName    = Your IT Department
   commonName                =
   emailAddress              =
   X509v3 extensions:
   X509v3 Basic Constraints:
   Netscape Comment:
   OpenSSL Generated Certificate
   X509v3 Subject Key Identifier:
   X509v3 Authority Key Identifier:

   Certificate is to be certified until Dec 22 18:52:38 2007 GMT (365 days)
   Sign the certificate? [y/n]:y
   1 out of 1 certificate requests certified, commit? [y/n]y
   Write out database with 1 new entries
   Data Base Updated
   Version: 3 (0x2)
   Serial Number: 1 (0x1)
   Signature Algorithm: sha1WithRSAEncryption
   Issuer: C=US, ST=Berkshire, O=My Secure Website Company, OU=Your IT Department, 
   Not Before: Dec 22 18:52:38 2006 GMT
   Not After : Dec 22 18:52:38 2007 GMT
   Subject: C=US, ST=Berkshire, L=Berkshire Hills, O=My Secure Website Company, 
   OU=Your IT Department,
   Subject Public Key Info:
   Public Key Algorithm: rsaEncryption
   RSA Public Key: (1024 bit)
   Modulus (1024 bit):
   Exponent: 65537 (0x10001)
   X509v3 extensions:
   X509v3 Basic Constraints:
   Netscape Comment:
   OpenSSL Generated Certificate
   X509v3 Subject Key Identifier:
   X509v3 Authority Key Identifier:
   Signature Algorithm: sha1WithRSAEncryption

Signed certificate is in newcert.pem

The certificate has now been self-signed and placed in the /etc/pki/tls directory. Both the private key and the certificate need to be renamed to better identify what server they represent so do the following:

# mv newcert.pem hostnameCert.prm
# mv newkey.pem hostnameKey.pem

That is it! Continue on to step 5 to configure Apache to use the newly created information.


Step 4B - The Trusted Certificate

To get a server certificate created by some third-party company like Thawte, VeriSign, GeoTrust, or, look for the certification request file that was created in step 3 (This file can be found in /etc/pki/tls/newreq.pem). Since each CA operates differently, you will have to research which way they want you to submit the data (also called the CSR by some websites)held within this file; however, most places have a simple on-line copy-and-paste procedure, or a file upload system. Once you have submitted the data held in the newreq.pem file you will be given back another batch of code similar to what you submitted. This snippet of code is your new signed/trusted certificate.

Once you have that code you will need to save it back to the /etc/pki/tls directory with a filename which makes it easily identifiable such as hostnameCert.pem

Once you have completed this step you are ready to move on to Step 5.


Step 5: Configuring Apache To Use Your Certificates

We must now configure the Apache server to utilize SSL. The first thing we will want to do is copy our newly made certificates to the proper location. Do the following:

# cd /etc/httpd/conf
# ls -al

In the listing, look for directories called ssl.key and ssl.crt. If they do not exist go ahead and make them:

# mkdir ssl.key ssl.crt

Once you have found or created the directories, it is time to copy our certificates over:

# cp /etc/pki/tls/hostnameCert.pem ssl.crt/server.crt
# cp /etc/pki/tls/hostnameKey.pem ssl.key/server.key

Once you have copied over the files, it is time to configure the Apache server to use them. Do this:

# cd /etc/httpd/conf.d
# ls -al

You should see a file called ssl.conf. Go ahead and open this file with your favorite editor. There are two thing that need to be changed in this file. They are around lines 112 and 119, it looks like this:

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/httpd/conf/ssl.crt/localhost.crt

# Server Private Key: # If the key is not combined with the certificate, use this # directive to point at the key file. Keep in mind that if # you've both a RSA and a DSA private key you can configure # both in parallel (to also allow the use of DSA ciphers, etc.) SSLCertificateKeyFile /etc/httpd/conf/ssl.key/localhost.key

Change the SSLCertificateFile path to the new path of /etc/httpd/conf/ssl.crt/server.crt. Then, we need to change the SSLCertificateKeyFile to the new path of /etc/httpd/conf/ssl.key/server.key. Once these changes are made save and quit the editor.

If we leave the configuration just as it is now, the SSL will work with a restart of the apache server. However, there is bit of a bump - each time we restart the httpd server it will ask us for the PEM passphrase. This is ok if you are constantly able to monitor the system, but for the sake of saving you that headache let's fix that problem. To fix this issue do the following:

# cd /etc/httpd/conf/ssl.key
# cp server.key server.key.orig
# openssl rsa -in server.key.orig -out server.key

You will be asked to enter the PEM pass phrase, so go ahead and input it and press enter. The program will finish and will have created the key file that will not require you to enter the PEM pass phrase on starting Apache. For security, we need to put security permissions on this file and restart the Apache server:

# chmod 700 server.key
# service httpd restart

If everything was done correctly, Apache will start with no problems. Now it is time to try out your new secure website. Open your browser and navigate to

If you decided to do a self-signed certificate, or one through you may get a message about the certificate not being trusted. This is normal and you should just tell the browser to accept the certificate. Once your on the website you should be able to view your certificate and the details on it.

Congratulations - you have just set up up an SSL secure website!

Share this page:

8 Comment(s)

Add comment


From: secure webmaster at: 2009-05-09 12:35:51

Thanks for this nice article. There are many reasons why security is the most important part of development. A small list for website security:

From: at: 2007-05-16 17:15:49

You really should disable weak ciphers and allow only high encryption algorithms. Default installs of Apache usually allow any cipher, even the horribly outdated ones. It is possible to force a downgrade of the server-side encryption level by sending a custom crafted SSL handshake. After that, it may be possible to exploit security holes in the weaker encryption protocols.

Enter the following in your httpd.conf or in the virtual host container. This will enable only the high encryption ciphers (TLSv1 or SSLv3). If you really need a secure environment, enable only TLSv1. Please note that some (very outdated) browsers may have problems with the higher cipher suites and will not be able to connect after this change.

SSLCipherSuite HIGH:-SSLv2

You can test if your server is vulnerable to this attack with the following command (using the openssl binary);

openssl s_client -no_tls1 -no_ssl3 -cipher LOW -connect

Replace the 255... IP address with your server' address of course. You should see a handshaking failure if everything is OK. If not, you will be presented with a certificate and you will see the actual cipher used (probably MD5 or something), which is bad.

The issue itself was brought to my attention by TNO, a Dutch research group which was contracted to do security auditing on a group of servers I administer. They should get the props for this.

From: at: 2007-05-28 11:59:46

This was a great help! I finally could make https work on my computer. However I found some typos that you must fix (as a newbye, I got a bit lost in a couple of steps).  I think you may rather to fix, instead of publish this comment (I do not mind if you don't give me this credit :-).

Instead of
# rm -rf ./../CA
I had to type
# rm -rf ../../CA

# cd /etc/httpf/conf/ssl.key
should be
# cd /etc/httpd/conf/ssl.key

Thanks a lot. 

From: at: 2007-05-29 13:56:00

Thanks pspsilveira, I will revise the document.  These are simple things I overlooked when I wrote it.

From: Anonymous at: 2009-01-16 14:17:54

Graet post, I wanted to add two things :

- ssl modules must be loaded in the httpd.conf. This is generally performed by adding :

LoadModule ssl_module         libexec/apache/
AddModule mod_ssl.c

- The VirtualHost directive can be used in case multiple websites are served by the same Apache instance for a fine-grained SSL configuration.

I also came across a similar article that discusses these topics :

From: Ian Channing at: 2009-06-03 11:45:39

This is a fantastic article that I use each time I'm generating a Server Certificate.  Only doing it each time the certificate needs renewing means I forget every time.

For a Trusted third party signing you only need steps 1,3,4B,5, i.e. you can leave out step 2 - this is just for signing the certificate request yourself.  For those like me, not really understanding the process and stepping through everything very carefully, knowing this would have saved me some time!

Perhaps this might be worth pointing out at the beginning?

From: Candace at: 2010-03-10 18:01:51

Love this howto - has so far helped me understand how to setup SSL on my servers. However I have a question on how to do configure Apache if you use a third party cert. You have the step: cp /etc/pki/tls/hostnameKey.pem ssl.key/server.key - but with the requests I submit, I do not get a key back, only a cert.

From: Bee at: 2010-12-16 03:47:36


 I followed this how-to and this just works great for me.