Add a password to your website or web directory

In my cases, you may want to add a password to one of your website or web folder.

For example in my case, I have a file.freedif.org website where I can simply download some files I’ve downloaded with my Deluge web-ui. This is done with Apache, where I simply have a virtualhost to link file.freedif.org to a folder with the Option +Indexes to display all the files.

But obviously I don’t want anyone else to access to this folder. Hence I’ve set up a simple username/password with the Apache htpasswd option.It can works with pretty anything, that does not includes per default a login system, like Yify-pop for the moment.

Here is how to do it.

1) Create a dedicated directory to store the password file

In Root, run

mkdir /etc/htpasswd

2) Create a password file with users

Still in root:

htpasswd -c /etc/htpasswd/.htpasswd user1

And you will need to enter a password

If you have multiple users, simply redo the command with user2, then user3, etc…

3) Modify your virtualhost

Now, you will need to edit (Or create) your virtualhost to add the authentication.

Inside the Directory path values

        <Directory />
                Options FollowSymLinks
                AllowOverride None
         </Directory>

add:

AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/etc/htpasswd/.htpasswd"
Require valid-user

Save and reload apache

/etc/init.d/apache2 reload

Now, everytime you navigate to the website linked to the modified virtualhost, Apache will ask you your username and password.

Gravatar

Loves to discover web-based apps to install on his own server@home and write articles about it

0 Comments:

Add a comment