If you can see this check that

  • Javascript is enabled

Basic Authentication

This tutorial is concerned with the configuration of Basic Authentication in apache.

If you recently did the previous tutorial, you should consider deleting the configuration file "/etc/httpd/conf.d/zvirtual.conf". Properly configured it makes no difference to this tutorial, but if there were errors in it or you experimented further with the config then it could cause issues.

To reset all the check buttons from a previous attempt click here

Question 1 Setup Basic Auth Scenario

Make sure your httpd.conf file supports User public_html directories. Look through the /etc/httpd/conf.d/userdir.conf file for a line:

  UserDir disable

Comment this line out (or delete it). Then look on a little further to find:

    #UserDir public_html

Delete (uncomment) the '#' comment character from the front of this line. As you have changed the configuration remember to reload the httpd service!

Make sure the apache service (httpd) is running, and it is running with the changes above.

Create a public_html directory in alice's home directory, and create a file p1.html in the public_html. The contents of this file should be:

<html>
<body>
<h1>ALICE</h1>
<p>
Document body goes here.
</p>
</body>
</html>

Change the appropriate permissions on the /home/alice and public_html directories and the files in public_html by the minimum amount possible to give apache the least permissions possible while still having access.

Finally, SELinux is enabled in enforcing mode by default. This means you need even more security to overcome (configure). You need to make sure that the SELinux boolean httpd_read_user_content is enabled. By default SELinux is forbidden from reading any file in /home. Check with

getsebool  httpd_read_user_content

and if needed set it with

setsebool -P httpd_read_user_content 1

"setsebool" may take a few seconds to run. It will finish, honest!

IN ALL CASES ENSURE alice owns ALL FILES AND DIRECTORIES in /home/alice AT ALL TIMES.

Tests: Ready
 
Apache Running UNTESTED
UserDir seems to be disabled UNTESTED
alice has a public_html which she owns UNTESTED
alice has a home directory executable by others UNTESTED
alice has a public_html executable by others UNTESTED
alice has a file p1.html which she owns UNTESTED
p1.html is readable by others UNTESTED
p1.html contains the word ALICE (case sensitive) UNTESTED
SELinux has been configured with httpd_read_user_content true UNTESTED
http://host/~alice/p1.html actually works UNTESTED

Question 2 Add two new directories/files

Create the following directories, each of which must be executable by others:

In each of these new directories create a file similar to p1.html, but called:

In "richard/p2.html" replace the word ALICE with RICHARD. In "harry/p3.html" replace the word ALICE with HARRY. Case is important.

Tests: Ready
 
Can read http://../~alice/richard/p2.html UNTESTED
http://../~alice/richard/p2.html contains RICHARD UNTESTED
Can read http://../~alice/harry/p3.html UNTESTED
http://../~alice/harry/p3.html contains HARRY UNTESTED

Question 3 Basic Auth file

Create a password file for basic authentication. Remember this has nothing to do with normal Linux users, and even less to do with /etc/passwd!

The htpasswd command allows you to create the file, and to add users to the file. Use it to create a basic authentication password file called "/home/alice/webpasswd". Put into this file two users with the following passwords:

User: richard              Password: pass1
User: harry                Password: pass2
Make sure that the password file is world readable. Give the file an SELinux context type of "httpd_user_content_t".
Tests: Ready
 
/home/alice/webpasswd exists and seems readable UNTESTED
/home/alice/webpasswd is httpd_user_content_t UNTESTED
Contents semi-sensible for richard? UNTESTED
Contents semi-sensible for harry? UNTESTED

Question 4 Secure richard/

Secure the public_html/richard directory so only a user with the basic authentication details of richard, password pass1, can access the files.

Tests: Ready
 
Basic Auth needed on ~alice/richard/p2.html UNTESTED
Basic Auth using richard/pass1 works for ~alice/richard/p2.html UNTESTED
Basic Auth using harry/pass2 fails for ~alice/richard/p2.html UNTESTED

Question 5 Secure harry/

Secure the public_html/harry directory so only a user with the basic authentication details of group "magic" can access the contents.

To answer this question, create a group file "/home/alice/webgroup" with the following contents:

magic: richard harry

The file needs an SELinux context type of "httpd_user_content_t". Make sure in the .htaccess file in the harry directory you use only "Require group" and not some sort of "Require user" command. And make sure all files in /home/alice are owned by alice...

Tests: Ready
 
/home/alice/webgroup exists and seems readable UNTESTED
/home/alice/webgroup is httpd_user_content_t UNTESTED
/home/alice/webgroup contains right magic: definition UNTESTED
No Require User in .htaccess UNTESTED
Using Require Group magic in .htaccess UNTESTED
Basic Auth needed on ~alice/harry/p2.html UNTESTED
Basic Auth using richard/pass1 works for ~alice/harry/p2.html UNTESTED
Basic Auth using harry/pass2 works for ~alice/harry/p2.html UNTESTED

Question 6 Complex requires/

  1. Add to your webpasswd file an extra user, "jim", with password "walton".
  2. Create a directory in public_html for "jim", called "jim", and create a file "p4.html" which is a copy of "p1.html" except you need to replace the word "ALICE" with "JIM".
  3. Protect this directory with basic authentication (similar to richard), but this time configure it so that that access is only permitted by either user "jim" from 10.200.0.1, or user "harry" from 127.0.0.1. Do not use any implicit requires (i.e. say RequireAny or RequireAll rather than relying on the defaults).
Tests: Ready
 
Jim seems to be in webpasswd UNTESTED
basic auth seems to be in the .htaccess file UNTESTED
Right no of requires test 1 UNTESTED
Right no of requires test 2 UNTESTED
User tests UNTESTED
IP tests UNTESTED
Basic Auth needed on ~alice/jim/p4.html UNTESTED
Basic Auth using jim/walton works for ~alice/jim/p4.html, 10.200.0.1 UNTESTED
Basic Auth using harry/pass2 fails for ~alice/jim/p4.html, 10.200.0.1 UNTESTED
Basic Auth using richard/pass1 fails for ~alice/jim/p4.html, 10.200.0.1 UNTESTED
Basic Auth using jim/walton fails for ~alice/jim/p4.html, 127.0.0.1 UNTESTED
Basic Auth using harry/pass2 works for ~alice/jim/p4.html, 127.0.0.1 UNTESTED
Basic Auth using richard/pass1 fails for ~alice/jim/p4.html, 127.0.0.1 UNTESTED

Alma 10 introPaths | BasicShell | Search
Alma 10 tutorials:intro1 | intro2 | wildcard | permission | pipe | vi | essential | admin | net | SELinux1 | SELinux2 | fwall | DNS | diag | Apache1 | Apache2 | log | Mail
Caine 10.0Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam
Caine 13.0Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Registry | Mock Exam
Kali 2020-41a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10
Kali 2024-41a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10
UsefulPrivacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2026 Edinburgh Napier University