Working with OpenSSL and Httpd

1 hour
  • 4 Learning Objectives

About this Hands-on Lab

Approximately 25% of the LPIC-3 Security exam is based on cryptography and how to employ it in Linux. In this hands-on lab, we will learn how to generate a signed certificate using `openssl` and use that certificate to secure HTTP traffic. We will then use the `openssl` command to verify the Apache configuration.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Install `mod_ssl` on the host `webserver`.

Run yum install mod_ssl, and accept the prompts.

Generate and sign the private key for `` using `openssl`.
  1. Create a new encrypted private key.
    openssl genrsa -aes128 -out /etc/pki/tls/private/httpdkey.pem
  2. Enter httpd at the passphrase prompt.
  3. Generate a self-signed certificate using the key.
    openssl req -new -x509 -key /etc/pki/tls/private/httpdkey.pem -out /etc/pki/tls/certs/httpdcert.pem -days 365
  4. Enter httpd at the passphrase prompt.
  5. At the prompts, enter the field information provided in the instructions (use defaults where not specified).
Update the default Apache virtual host to accept connections on `` using the new keypair, and allow HTTPS traffic through the firewall.
  1. Make the following changes to /etc/httpd/conf.d/ssl.conf:

    • At the end of the <VirtualHost _default_:443> section, add the following on a new line:
      • ServerName
    • Locate the line SSLCertificateFile /etc/pki/tls/certs/localhost.crt, and change it to the following:
      • SSLCertificateFile /etc/pki/tls/certs/httpdcert.pem
    • Locate the line SSLCertificateKeyFile /etc/pki/tls/private/localhost.key, and change it to the following:
      • SSLCertificateKeyFile /etc/pki/tls/private/httpdkey.pem
  2. Restart httpd to put the changes into effect.

    systemctl restart httpd
  3. Enter httpd at the passphrase prompt.

  4. Open port 443 on the OS firewall.

    sudo firewall-cmd --add-service=https --permanent 
    sudo firewall-cmd --reload
Verify the configuration with `openssl` from the host `workstation`.
  1. On the workstation machine, run the following command:
    openssl s_client -connect > /home/cloud_user/httpd_output

    Note: The OpenSSL s_client will briefly wait for input before terminating the connection. You may either interrupt the running command or let it close automatically. No further input is required.

Additional Resources

There is a request to stand up a new proof-of-concept website that will support your company's upcoming online store. You will need to install mod_ssl on the test webserver and configure the default virtual host to be secured with a self-signed certificate for testing.

The virtual host should be accessible at on the host webnode. The virtual host should operate over SSL using a 2048-bit self-signed private key. The key should be encrypted using AES128 and stored in /etc/pki/tls/private/httpdkey.pem on the webserver host using the passphrase httpd. The self-signed certificate should be stored in the file /etc/pki/tls/certs/httpdcert.pem on the webserver host.

You will need to allow HTTPS traffic through the OS-level firewall on port 443. This may be completed by running the following commands on the web server host:

sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload

Once the virtual host and firewall access have been configured, verify that your configuration works by using the openssl s_client command. Output the secure connection information to /home/cloud_user/httpd_output on the host workstation.

Note: The httpd package has been installed on the host webserver. OpenSSL has been installed on both hosts. The hosts file has been modified to allow use of the hostnames webserver and workstation along with the domain when connecting from workstation. There is a pre-shared key for cloud_user that allows for key authentication when connecting to webserver from workstation.

Summary tasks list:

  • Install mod_ssl on the host webserver.

  • Generate and sign the private key for using openssl. The key should be AES128-encrypted with the passphrase httpd, and the key should be 2048 bits. The certificate should be in x509 format and valid for 365 days. The keys should be located as mentioned above. The x509 fields should use the following information:

    • Country Name (2 letter code) [XX]: US
    • State or Province Name (full name) []: Texas
    • Locality Name (eg, city) [Default City]: Dallas
    • Organization Name (eg, company) [Default Company Ltd]: Example Corp
    • Organizational Unit Name (eg, section) []: <blank>
    • Common Name (eg, your name or your server's hostname) []:
    • Email Address []:
  • Update the default Apache virtual host to accept connections on using the new keypair, and allow HTTPS traffic through the firewall.

  • Verify the configuration with openssl from the host workstation by using openssl s_client to connect to your virtual host. Output the connection information to /home/cloud_user/httpd_output on the host workstation.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?