Difference between revisions of "Password protect directories using htaccess"
Line 9: | Line 9: | ||
To become root. The root password is | To become root. The root password is | ||
<pre>excito</pre> | <pre>excito</pre> | ||
Edit your sites-file: | |||
<pre>nano /etc/apache2/sites-enabled/bubba</pre> | <pre>nano /etc/apache2/sites-enabled/bubba</pre> | ||
You will find the part (observe <Directory /home/web/>) in two places: | |||
<pre><Directory /home/web/> | <pre><Directory /home/web/> | ||
Options Indexes FollowSymLinks MultiViews | Options Indexes FollowSymLinks MultiViews | ||
Line 18: | Line 18: | ||
allow from all | allow from all | ||
</Directory></pre> | </Directory></pre> | ||
Edit it in both places to: | |||
<pre><Directory /home/web/> | <pre><Directory /home/web/> | ||
Options Indexes FollowSymLinks MultiViews | Options Indexes FollowSymLinks MultiViews | ||
Line 25: | Line 25: | ||
allow from all | allow from all | ||
</Directory></pre> | </Directory></pre> | ||
Now you need to restart the webserver.<br> | |||
<pre>/etc/init.d/apache2 restart</pre> | <pre>/etc/init.d/apache2 restart</pre> | ||
Create a .htaccess file in the web catalog you want to password protect: | |||
<pre>nano /home/web/protectedfiles/.htaccess</pre> | <pre>nano /home/web/protectedfiles/.htaccess</pre> | ||
(Where protectedfiles is the catalog you will protect in this example.) | (Where protectedfiles is the catalog you will protect in this example.) | ||
Line 44: | Line 44: | ||
Create a catalog to place your password file in:<br> | Create a catalog to place your password file in:<br> | ||
<pre>mkdir /etc/.passwords</pre> | <pre>mkdir /etc/.passwords</pre> | ||
To create the file containing the passwords for the users, type:<br> | |||
<pre>htpasswd -c /etc/.passwords/.htpasswd user1</pre> | <pre>htpasswd -c /etc/.passwords/.htpasswd user1</pre> | ||
You now have to enter a password for the user "user1". | You now have to enter a password for the user "user1". |
Latest revision as of 10:27, 28 December 2010
Password protect directories using htaccess
Author: Magnus
A guide on how to enable password protection in your web catalogs on your Bubba Two.
Using ssh, log on to Bubba (as your regular user). Type
su
To become root. The root password is
excito
Edit your sites-file:
nano /etc/apache2/sites-enabled/bubba
You will find the part (observe <Directory /home/web/>) in two places:
<Directory /home/web/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory>
Edit it in both places to:
<Directory /home/web/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
Now you need to restart the webserver.
/etc/init.d/apache2 restart
Create a .htaccess file in the web catalog you want to password protect:
nano /home/web/protectedfiles/.htaccess
(Where protectedfiles is the catalog you will protect in this example.)
A "standard" .htaccessfile could look something like:
AuthType Basic AuthName "Password Required" AuthUserFile /etc/.passwords/.htpasswd Require user user1
(Where user1 is the username you log in with in this example.)
Save your .htaccessfile.
To password protect more catalogs simply create and place one .htaccessfile in every catalog you need to protect. Remember to change the user1 to whatever user you desire.
Create a catalog to place your password file in:
mkdir /etc/.passwords
To create the file containing the passwords for the users, type:
htpasswd -c /etc/.passwords/.htpasswd user1
You now have to enter a password for the user "user1".
To add more users in the .passwords file, leave out the -c parameter:
htpasswd /etc/.passwords/.htpasswd user2
You now have to enter a password for the user "user2".
Open a web browser and brows to your protected catalog: www.yourbubba.com/protectedfiles. You should have to enter user name "user1" and your selected password.