How do I password protect my webpages?
- Make sure all of your pages are in one directory (folder) and that the correct permissions have been set ( How do I do that? )
- Open a terminal session ( How do I do that? ) and log-on to the account you are working with
- Change directory (use the command cd directoryname substituting the name of your folder) until you are in the directory you wish to password protect
- Choose a username and password for people to use when accessing the directory. These must not be the same as the account or your own username and password.
- Type in htpasswd -c.htpasswd username where username is the name you have decided people will use to access your directory
- You will then be asked to enter and confirm the password you want to use
- This creates a file called .htpasswd in your directory, which checks the information put in by the user at the other end
- Set permissions on the .htpasswd file by typing in chmod 644 .htpasswd and press return
Once this is done, you will need to create a file called .htaccess. This file verifies information put into the username and password box. To create the .htaccess file:
- Type pico to open a text editor
- Enter the text below into pico, replacing the highlighted text with the details for your directory
- AuthUserFile /aber/your_username/public_html/restricted_directory/.htpasswd
AuthName "Restricted Data"
require user username
your_username is either your personal 3, 4 or 5 letter login or your departmental Web account
restricted_directory is the name of the directory you have chosen to restrict
username is the username you chose for the people accessing the directory
- Save this file by using Ctrl+O and entering a file name
- Set the permissions on the .htaccess file by typing in chmod 644 .htaccess and press return
The password protection is in place. When anyone tries to load up the page, their web browser will display a box asking for their username and password.
Information Services, Aberystwyth University, Hugh Owen Library, Penglais, Aberystwyth, SY23 3DZ
Tel: 01970 62 2400 Email: firstname.lastname@example.org