If you want to restrict access to one of your web directories on a Unix server, the simplest way to do it is to create a .htaccess file in that directory.
Note: in what follows, you will create an htaccess-username and an htaccess-password. These are different from and not to be confused with your DuckID username and DuckID password.
Example: htpasswd -c htpasswd 111
Replace htaccess-username with the htaccess-username you need to use for password access. For our class, we will all use the class number (110, 111, 122 or 382) as the htaccess-username.
In the command, the second occurrence of the word htpasswd is the name of the password file. Use this file name. The -c switch creates the file htpasswd if it does not exist. If the file does exist, the -c switch first deletes the existing file and then creates a new one. If you have already used this command to create an htpasswd file in another CIS class, then omit the -c switch.After you do this, a filename htpasswd will be created in your Unix home
directory; the file stores HTACCESS usernames and HTACCESS passwords.
If an instructor in another class wants to you use HTAccess for that class, you can add entries to this file later by
using the htpasswd command shown above, but this time omitting the -c switch:
htpasswd htpasswd 199
This command adds an htaccess-username for a course numbered 199 to the existing htpasswd file.
cd public_html/secure_directory
pico .htaccess
It should include the following lines:
(Note that the entries you make in this file are case sensitive and cannot include spaces, unless the entries are surrounded by quotation marks.)
AuthUserFile /home13/joeuser/htpasswd
AuthGroupFile /dev/null
AuthName "Joe User" (quotes are used since this is a two-word phrase)
AuthType Basic
require user joeuser
Your browser will prompt you to enter the htaccess-username and htaccess-password.
If you are successful, you will see the web page you were trying to access. If you get an error message, make sure you entered the name and password correctly, and check that the .htaccess file contains the correct username in the require user line.