Wadah Belajar Linux, Debian, Mikrotik, Networking, Routing, dan Ilmu Pendukungnya

< Browse > Home / Linux, script / Blog article: Protect a Directory on Your Website with htaccess and htpasswd

| Mobile | RSS

Protect a Directory on Your Website with htaccess and htpasswd

October 20th, 2008 | 2 Comments | Posted in Linux, script

htaccess is a way to password protect directories. It can also be used to give user or group specific access to directories. This guide will tell you how to setup apache for htaccess and to set up basic protection. Let’s begin.

Open up /etc/apache2/sites-available/default

# vim /etc/apache2/sites-available/default
find the lines that look like the following:

<Directory “/var/www”>
Options Indexes FollowSymLinks MultiViews +SymlinksIfOwnerMatch
IndexOptions NameWidth=* +SuppressDescription
AllowOverride None
Order allow,deny
allow from all
</Directory>

In order to use htaccess, you’ll need to change the line

AllowOverride None

To

AllowOverride AuthConfig

Now restart apache for the changes to take effect.
# /etc/init.d/apache2 restart

Create a file in the dir you want to protect called .htaccess
# vim /var/www/.htaccess

AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
AuthName “Zulfan Test Login”
AuthType Basic
require valid-user

To create an initial .htpasswd file, use the -c tag.
The syntax is: htpasswd passwordfilename user (add -c if you’re creating the file)
# htpasswd -c /var/www/.htpasswd zulfan
New password:
Re-type new password:
Adding password for user zulfan

To create new users in the same file, simply drop the -c.
# htpasswd /var/www/html/.htpasswd guest
New password:
Re-type new password:
Adding password for user guest

When running htpasswd it will ask you for that username’s password. Now, everything should be set up, and your directory should be protected.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogosphere News
  • Live
  • MisterWong
  • MySpace
  • Ping.fm
  • Slashdot
  • StumbleUpon
  • Technorati
  • Print
  • email
Leave a Reply 2588 views, 3 so far today |

Related Posts

Follow Discussion

2 Responses to “Protect a Directory on Your Website with htaccess and htpasswd”

  1. a3m-nix Says:

    thanks, nice article :D

  2. Sari Says:

    wah trima kasih atas artikel nya :)

Leave a Reply



View My Stats