| How-to
Password Protect Your Web Space Computing Resources >> Tutorials >> Web Development >> How-to Password Protect Your Web Space |
Protecting DirectoriesNow that you have created your file of users and passwords, move into
your public_html directory with the command: echo $HOME
This command will return something that looks like /export/home/u98/login,
where login is your user name. The full path of the file we created in
step 1 is going to be the result of that command with the name of the
file tacked onto the end. It can be easy to forget, so you might want
to write it down. In the end, it should look something like, /export/home/u98/joeblow/htusers.Now, using a text editor, create a file called .htaccess (yes, there is a period in front of that). For pico users, you can type: pico .htaccess
This will put you into a blank pico editing screen. Now you want to add several entries to your file. Each of these entries consists of a directive followed by a value. These are like attribute/value pairs in HTML. First, you want to give the area you're protecting a name. To do this we use a directive called AuthName, so our first line might look
like: AuthName "My Web Stuff"
Next, we need to specify what type of authentication we are using, and where the file is located. This is where we need the line from above. So, the next two lines would look like: AuthType Basic
Finally, we tell the server what is required for someone to have access to this area of our web space. So we add a final line that says: require valid-user
This says that any user listed in the htusers file that provides a valid password will be allowed in. So, all told, our .htaccess file should look something like: AuthName "My Web Stuff"
Now, save your file and exit the text editor. In pico, Ctrl-X will do this. Finally, once you're back at the prompt, type: chmod 644 .htaccess
This makes sure the web server can read your .htaccess file. The setup above will password protect every file in your html directory,
as well as any files in subdirectories. If that's exactly what you want,
you can stop here, but often people are interested in limiting access
only to certain files or certain subdirectories. By changing the location
of the .htaccess file and/or the contents of the file, you can create
more intricate configurations. mv .htaccess classwork
|
Watch the video |