|
Home
Allowing password access for individual users
IntroductionThe following is a detailed example of how you would set up an htaccess file to allow password restricted access for individual users to part of a Commercial Web Site. If you need to do this for groups of users, please read Allowing Password Access for Groups of Users. You will need to be familiar with some of the Unix commands described in the Using UNIX section to proceed. Set up the directoriesTELNET 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 fileNow we will create an htaccess system that allows password access for a user called Alfred to the protected directory. On your computer, use a simple text editor to create a file called access.txt and insert the following text:
... where "your-hostname" is your registered domain name, eg. yourcompany.co.uk or yourcompany.com etc. Note that we are going to place the .htpasswd file in the cgi-files/passwords directory. This is the most secure place to put this file. N.B. There must be a blank line at the bottom of the access.txt file. Place the htaccess fileMake an FTP connection to your website and transfer the access.txt file to your protected directory. Remember to FTP the file in ASCII or Text transfer mode - it is to be read directly by the server so it must be in Unix format. Please read the documentation about uploading your pages if this is unclear to you. You now need to rename the file to make it function. In TELNET change directory to the protected directory and type:
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:
Make the htpasswd fileChange directory to the cgi-files/passwords directory. Type the following at the prompt:
This stage prompts you to enter a password - choose one, but remember that it is case-sensitive. A file called .htpasswd will be created. Again you will not see this file unless you use "ls -a". You do not need to chmod this file. Test the setupCopy 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 a "Server Error" message, check that the access.txt file has the correct format and has been copied to the correct location and name. Adding more usersTo add further users (for example Batman and Catwoman) you need to edit the "require user..." line in the access.txt file, eg.
You must then transfer the update to the protected directory, rename and chmod as before. Again the next step is to use the htpasswd command in the cgi-files/passwords directory, but this time without the "-c" switch, eg.
Each user will have a separate password. If you need to extend this to a large number of users, it may be better to set passwords for groups of users. Please read Allowing Password Access for Groups of Users for details.
|
©Copyright 2008 THUS plc
|