A simple Example of how to setup your .htaccess file and .htpasswd



Goto your home directory and then goto public_html directory there. Make a new directory called admin. Make a new file called .htaccess.

A copy of .htaccess will look like as below

AuthUserFile /home/students/s611993a/.htpasswd  - This will the full path of your home directory
AuthGroupFile /home/students/s611993a/public_html/admin/.htgroup   - This will be the Path of the folder where the group file exits
AuthName "Saiful's Admin Page" - Grettings you want to be displayed
AuthType Basic
Require user username
[Require valid-user]
[Require group groupname]

The command to setup .htaccess password is(run this command under your home directory or at your public_html directory) . This command will create the .htpassword file for you.

/var/lib/apache/bin/htpasswd -c .htpasswd username

where username is the username you will mention in your .htaccess file.

Try the following link and see how it works
Test Page
Use username as "mytest" and Password as "MyTest"

To add more than one user's password

/var/lib/apache/bin/htpasswd  .htpasswd username

Just omit the -c

To make the .htgroup file

Create a file under your /public_html/admin/ called .htgroup and add the following

groupname :  user1 user2 user3 .......

Remember this groupname and the groupname in your .htacess must be the same.

NOTE: Remember to close you browser once you give the password on .htaccess as it keeps it on the memory. So if you don't close the browser the security issue might occur.