Skip to main content

Configure Directory and File Access and Add Basic Authentication

Hands-On Lab

 

Photo of

Training Architect

Length

01:30:00

Difficulty

Intermediate

In this lab, we go over the fundamentals of directory and file access. The idea of this lab is to overwrite the default configuration and allow access to the two files in the DocumentRoot with .htaccess. On top of this, we need to cover basic authentication and IP-based access.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Configure Directory and File Access and Add Basic Authentication

Introduction

In this lab, we go over the fundamentals of directory and file access. The idea of this lab is to overwrite the default configuration and allow access to the two files in the DocumentRoot with .htaccess. On top of this, we need to cover basic authentication and IP-based access.

Connecting to the Lab

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page.

    ssh cloud_user@PUBLIC_IP_ADDRESS

Create the Access File

  1. Log in as root. This step was done before the lab video started.

    su
  2. Create the file.

    touch /var/www/html/.htcaccess

Configure Authentication and Access

  1. Create a user and enter a password.

    htpasswd -c /var/www/htpasswd Joe
  2. Edit the .htaccess file.

    vim /var/www/html/.htaccess
  3. Add the following to the file.

    AuthType Basic
    AuthName "Restricted Files"
    AuthBasicProvider file
    AuthUserFile "/var/www/htpasswd"
    Require user Joe
    Require ip 
    1. Determine your IP address. One way is to open a browser and search for "What is my ip".

    2. Add your IP address to the .htaccess file after "Require ip ". Make sure to include a space after "ip".

    3. Save the changes and quit the editor.

Test the Results

  1. Open a browser and navigate to the public IP address provided in the lab instructions. Verify access to the site.

  2. Require a password when accessing the site.

    1. Open the .htaccess file.

      vim /var/www/html/.htaccess
    2. Remove the last line that starts with "Require ip".

    3. Save the changes and quit the editor.

    4. Reload the browser window and verify the ability to log in with the username and password provided in the previous task.

Conclusion

Congratulations, you've completed this hands-on lab!