How-to Password Protect Your Web Space
Computing Resources >> Tutorials >> Web Development >> How-to Password Protect Your Web Space 


Create Username and Password

Protecting Directories

Protecting Individual Files

Evaluate this tutorial

Create Username and Password

First, you must log into your School of Information account using SSH Secure Shell (for a PC) or Terminal (for a Mac). Now, you need to set up a file that contains user / password pairs. In order to do this, we use a program called htpasswd. First, move into your home directory. If you're not sure where you are, type:

    cd $HOME

Now we can create a new file using htpasswd. htpasswd takes two arguments: the name of the file with the user / password pairs, and a user name to add to the file. If we are creating a new file, we include a -c. So if we want to create a new file called htusers and add an initial user named guest, we type:
    htpasswd -c htusers guest

You can of course replace htusers and guest with names you prefer. htpasswd will prompt you for a password to associate with this username, which you should enter in. Once htpasswd is done and you see the prompt again, if you type:
    cat htusers

you will see the contents of the new file. What you will see is the username, followed by a colon, and then a string of meaningless letters and numbers. These letters and numbers are the encrypted password. To add more users, you can type:
    htpasswd htusers another

To change the password associated with a user name, run htpasswd with that name and it will prompt you to change it. Once you have created your file, you need to set the permissions so that the web server can read it. To do so, type:

    chmod 644 htusers

next section >

Watch the video

choose format/speed
dial-up | broadband
dial-up | broadband
dial-up | broadband

© 2003 Shane Williams| iSchool | UT Austin | webmaster