Monthly Archives: September 2008

Protect web pages with username/password

If there some web pages you want to protect with username/password, all you have to do is to create a file called .htaccess under the directory to protect with the following lines:

  2. AuthUserFile /path/to/htpasswd/.htpasswd
  3. AuthGroupFile /dev/null
  4. AuthName "Restricted Directory"
  5. AuthType Basic
  7. <Limit GET POST>
  8. require valid-user
  9. </Limit>

Replace /path/to/htpasswd/ with the .htpasswd path.
Replace Restricted Directory with the text you want as title of the prompt window.

Then you have to create the .htpasswd file using the following command:

htpasswd -c .htpasswd user_name

Execute it under the directory to protect or add the full path to .httpasswd and replace user_name by the username you want to use, you will be asked to enter the password and the file will be created.

Notes: This instruction are for linux/unix systems using apache web server, the dot means hidden files on linux.