Mohammedz.com

For Linux and Shell scripting.

How to Password Protect your Web Pages

Leave a comment


If you want to provide password protection for your webpages, follow the steps below:

Create a .htaccess file under the directory (which you want to protect):

To protect the entire directory

AuthName “Restricted Area”
AuthType Basic
AuthUserFile /docroot/<username>/.htpasswd
AuthGroupFile /dev/null
require valid-user

To protect individual files like test.html, testing.html:

AuthName “Restricted Area”
AuthType Basic
AuthUserFile /docroot/<username>/.htpasswd
AuthGroupFile /dev/null
<Files test.html>
require valid-user
</Files>
<Files testing.html>
require valid-user
</Files>

docroot/username/.htpasswd is the file where you want to put the username(s) and encrypted password(s).

You can create this “htpasswd” file using the command:

#htpasswd -nb username testpass

This command will give you an output like username:P/X0BsSU.aEKM Put this line to your .htpasswd file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s