Knowledgebase

Setting up directory authentication using .htaccess

Setting up directory security using .htaccess

First create a password file:
> htpaswd -c /var/www/passwd adam
The command will ask you for a password, and create a file /var/www/password, and adds a user called adam. If the file already exists the "-c" option will remove all content first.

To and next user just skip the -c option (same command for updating passwords):
> htpaswd /var/www/passwd adam2



To password protect directory /var/www/mysite/admin

Just put .htaccess file in that directory with the content:

AuthType Basic
AuthName "Admin"
AuthUserFile "/var/www/passwd"
require valid-user

Make sure the file is readable by webserver:
> chmod 644 /var/www/mysite/admin/.htaccess

You can also create a group file, for example:

echo "admin: adam, adam2" > /var/www/group

Then put the following content into var/www/mysite/admin/.htaccess file:

AuthType Basic
AuthName "Admin"
AuthUserFile "/var/www/passwd"
AuthGroupFile "/var/www/group"
Require group admin
Post Date: 2015-02-12 13:14:04 · Tags: Knowledgebase,

Article Topics

Apache
 . . .SSL (1)
Mysql (2)
SOLR (1)
Oracle (4)
Unix (2)
 . . .Command Line (1)

Quick Contact

Phone: 608-320-9321

pdf document opens new tab Resume

LinkedIn opens new tab LinkedIn Profile

Payments opens new tab Online Payments