|
Password Protected Web Pages on comp.uark.edu
Use .htaccess on comp.uark.edu to password protect a subdirectory in your account. You will create the username and password.
- Create the directory to be password protected. Even if you just want to protect one web page or file, you need to create a new directory. If you apply this protection at the root of your account, then your entire web site will require a password before it can be viewed on the Web. All files in the subdirectory will be subject to the password protection. To create the directory to be password protected, SSH to your account (SSH Secure Shell for Windows or Macintosh SSH).
- Change to the public_html directory by typing:
cd public_html
- To make a directory, at the server prompt, (comp% unless you've changed your default shell) type:
mkdir directoryname where "directoryname" is the name that you have chosen for the new directory. Press Enter, and you will be returned to the server prompt.
- Make sure that permissions are set on your new directory. Type:
chmod a+rx directoryname/ where "directoryname" is the name that you have chosen for the new directory.
- Now you need to change into that directory. Type:
cd directoryname where "directoryname" is the name that you have chosen for the new directory.
- Find your path from the server root. From the directory you created, type:
pwd which will return a path that will resemble this example: /export/home1/comp/username/public_html/directoryname/ where "directoryname" is the name that you have chosen for the new directory.
- Copy the path; you will need it for the .htaccess file. (Since you will probably also copy/paste the code into the file, you might want to do that first, exit and save the file, copy your path, and reopen the file, and paste in the path.)
- Create the .htaccess file in your account using Pico, a Unix text editor. At the server prompt, type:
pico .htaccess to open a blank file.
- Type or copy the following into the file:
Make sure that none of the lines wrap. Replace "/export/home1/comp/username/public_html/directoryname/" with your path. Make sure there is one space after "AuthUserFile" and no spaces or quotes in the path to the .htpasswd file. The name given for "AuthName" (Window Name) is the name on the login box that pops up for authentication. Replace "username" with the login username of your choice.
- Exit the file by pressing keys Ctrl and x. It will prompt you to "Save the Modified Buffer". Press y for yes. Then it will ask "File name to write:". Press Enter to accept the name you already assigned it.
- Next, you will create the .htpasswd file and assign an encrypted password to the username you choose. At the server prompt, type:
htpasswd -c .htpasswd username where "username" is the username that you typed into the .htaccess file. You will be prompted twice to enter the password for the directory. You have the option to use more than one username and each with seperate passwords. To add another username to the list at the server prompt, type: htpasswd .htpasswd username Note: The "-c" operator creates the file each time, so if you use it a second time it will overwrite the previous .htpasswd file.
- Finally, you need to set read permissions on both of the files just created. At the server prompt, type:
chmod a+r .ht* Note: The star is a wildcard and will allow the statement to work on both files. You can close SSH (exit) and test your web page. From now on, any web page or file you put in that directory will be password protected.
|