About usContact usSite help
Quick links
Search this site

Allowing password access for groups of users

Introduction

The following is a detailed example of how you would set up an htaccess file to allow password restricted access for groups of users to part of a Commercial website. This makes it easier to set access rights for a whole group of people in one go, without having to make a lot of updates to htaccess file(s). If you instead need to set passwords for individual users, please read Allowing Password Access for Individual Users. You will need to be familiar with some of the Unix commands described in Setting up your Web Pages to proceed.

Set up the directories

TELNET into your site and create a directory in your docs directory (using mkdir). In this example we'll call it protected. You will also need to create another directory which we will call passwords in the cgi-files directory.

Create the htaccess file

Now we will create an htaccess system that allows password access for a group of users called Dailyusers to the protected directory. On your computer, use a simple text editor to create a file called access.txt and insert the following text:

AuthUserFile /cgi-files/www.your-hostname/passwords/.htpasswd
AuthGroupFile /cgi-files/www.your-hostname/passwords/.htgroup
AuthName "Restricted Access"
AuthType Basic

<Limit GET>
require group Dailyusers
</Limit>

... where "your-hostname" is your registered domain name, eg. yourcompany.co.uk or yourcompany.com etc.

N.B. There must be a blank line at the bottom of the access.txt file.

Create the htgroup file

We now need to specify who are the Dailyusers. Again using a simple text editor create a file called group.txt and insert the following text:

Dailyusers: Clark Jimmy Lois

... where Clark, Jimmy and Lois are the user names.
N.B. There must be a carriage return after the last user name.

Place the htaccess and htgroup files

Make an FTP connection to your website and transfer the access.txt file to your protected directory. Then transfer the group.txt file to your cgi-files/passwords directory in a similar way. Remember to FTP these files in ASCII or Text transfer mode - they are to be read directly by the server so they must be in Unix format. Please read the documentation about uploading your pages if this is unclear to you.

You now need to rename and chmod the files to make them function. In TELNET change directory to the protected directory and type:

mv access.txt .htaccess

Please note, once you rename the file it will not be shown when you use "ls" to list the directory contents. Instead you can use "ls -a" or "ls -la" to see its details.

You now need to chmod the .htaccess file in your protected directory in order to activate it. Type:

chmod 604 .htaccess

For the htgroup file, change directory to the cgi-files/passwords directory and type:

mv group.txt .htgroup

The .htgroup file has to go through a chmod stage similar to the one for .htaccess:

chmod 604 .htgroup

Make the htpasswd file

Change directory to the cgi-files/passwords directory, if necessary. Type the following at the prompt:

htpasswd -c .htpasswd Clark

This stage prompts you to enter a password - choose one, but remember that it is case-sensitive. A file called .htpasswd will be created.

For each subsequent user you need to use the same htpasswd command, but this time without the "-c" switch, eg.

htpasswd .htpasswd Jimmy
htpasswd .htpasswd Lois

Again you will not see this file unless you use "ls -a". You do not need to chmod the file.

Test the setup

Copy an existing HTML or other standard file type to your protected directory. chmod it if necessary. Now start up your browser and try to access the directory, or the file within it - you should be challenged for a username and password. If there is no challenge, check that you have performed the chmod step on the .htaccess file. If you get repeated "Authorization Required" warnings, try doing the htpasswd command again for all the users. If you get a "Server Error" message, check that the access.txt and group.txt files have the correct format and have been copied to the correct locations and names.

Adding more groups or users

To add further groups (for example Goodguys) you need to edit the "require group ..." line in the access.txt file, eg.

require group Dailyusers Goodguys

A new line would also need to be added to the group.txt file, eg.

Goodguys: Alfred Batman Catwoman

N.B. Remember, there must be a carriage return after the last user name.

You must then transfer the updates to the protected and cgi-files/passwords directories respectively, rename and chmod as before. Again the next step is to use the htpasswd command in the cgi-files/passwords directory without the "-c" switch, eg.

htpasswd .htpasswd Alfred
htpasswd .htpasswd Batman
htpasswd .htpasswd Catwoman

Alternatively these same names could be added as individual users, instead of as a group. Just add a "require user ..." line after the "require group ..." line in the access.txt file, eg.

require user Alfred Batman Catwoman

Again the next step is to use the htpasswd command for each user's password.


More Help





*