Tuesday, December 1, 2009

HTTP Basic Auth

As while working with apache many of us feel like having a secure way to access our data.
Simple but effective http basic auth is probably the quickest and the easiest answer.

Setting it up requires only two things:
- htpasswd file (containing valid user name and password)
- And apache configuration file to read it.

Creating a htpasswd file:
- htpasswd -cm </Path/tp/htpasswd-file> <username>
- While adding more users just remove c from the above command.

Configuring apache:
- Add this to default (vhost file) configuration file
           Allow from all
           AuthType Basic
           AuthName "Restricted Area"
           AuthUserFile </Path/to/htpasswd-file>
           Require valid-user

- Now reload apache and enjoy.