Proteksi Web Direktori Menggunakan htaccess dan htpasswd
File htaccess berguna untuk melakukan authenticate user tingkat web server, oleh karena itu file htaccess harus di configure juga di /etc/apache2/sites-available/default (file configurasi site apache2).
# vim /etc/apache2/sites-available/default
cari bagian :
<Directory “/var/www”>
Options Indexes FollowSymLinks MultiViews +SymlinksIfOwnerMatch
IndexOptions NameWidth=* +SuppressDescription
AllowOverride None
Order allow,deny
allow from all
</Directory>
Supaya bisa memakai htaccess harus merubah :
AllowOverride None
menjadi :
AllowOverride AuthConfig
Setelah dirubah, save dan restart si apache :
# /etc/init.d/apache2 restart
Buat file .htaccess, contoh kali ini kita buat di folder /var/www
# vim /var/www/.htaccess
AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
AuthName “Zulfan Test Login”
AuthType Basic
require valid-user
Menggunakan htpasswd utk bikin file data user yg boleh akses, utk yg pertama kali dengan menggunakan opsi -c, misal :
# htpasswd -c /var/www/.htpasswd zulfan
New password:
Re-type new password:
Adding password for user zulfan
Utk menambahkan user lain :
# htpasswd /var/www/html/.htpasswd guest
New password:
Re-type new password:
Adding password for user guest
Silahkan dicoba.




