Skip to content

htaccess password – apache

htaccess password

apache

To protect a folder against unauthorized access via a webbrowser you need to follow a couple of simple steps.

Place a .htaccess file in the folder you want to protect with the following directives:

AuthUserFile /FULLPATHTOYOURPASSWORDFILE/.htpasswd
AuthGroupFile /dev/null
AuthName “Please Login First”
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>

Do not forget to make sure that you have write access to the full path where you want to store your password file. Note on security it is better not to store the .htpasswd in your webroot. Store it in a folder below your webroot whenever possible.

Then do the following on the command line

cd /var/www/FULLPATHTOYOURPASSWORDFILE

Now you can create the password file for the first time with the apache tool “htpasswd” you will be prompted to enter the new password for the user 2 times.

htpasswd -c .htpasswd username

To add more users do the following:

htpasswd .htpasswd username2

htpasswd .htpasswd username2

That’s it, now when you want to access this folder via a webbrowser you will be prompted for a password.

Rudolf Maduro (IT specialist)

Note: I assume no responsibility when the above information is used. Any damages to you or your users after using this procedure is your own responsibility. This information is given for educational purposes only.

Published inLinux

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *