Difference between revisions of "Password protect directories using htaccess"
(Created page with 'Password protect directories using htaccess<br> Author: Magnus<br> A guide how to enable password protection in your web catalogs on your Bubba Two. Using ssh, log on to Bubba...') |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Password protect directories using htaccess<br> | Password protect directories using htaccess<br> | ||
Author: Magnus<br> | Author: Magnus<br> | ||
A guide how to enable password protection in your web catalogs on your Bubba Two. | 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 | Using ssh, log on to Bubba (as your regular user). Type | ||
<pre> | <pre>su</pre> | ||
su</pre> | To become root. The root password is | ||
To become root. The root password is | <pre>excito</pre> | ||
<pre> | Edit your sites-file: | ||
excito</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/> | |||
Edit your sites-file: | |||
<pre> | |||
nano /etc/apache2/sites-enabled/bubba</pre> | |||
You will find the part (observe <Directory /home/web/>) in two places: | |||
<pre> | |||
<Directory /home/web/> | |||
Options Indexes FollowSymLinks MultiViews | Options Indexes FollowSymLinks MultiViews | ||
AllowOverride None | AllowOverride None | ||
Order allow,deny | Order allow,deny | ||
allow from all | allow from all | ||
</Directory></pre> | </Directory></pre> | ||
Edit it in both places to: | |||
<pre><Directory /home/web/> | |||
Edit it in both places to: | |||
<pre> | |||
<Directory /home/web/> | |||
Options Indexes FollowSymLinks MultiViews | Options Indexes FollowSymLinks MultiViews | ||
AllowOverride All | AllowOverride All | ||
Order allow,deny | Order allow,deny | ||
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> | |||
Now you need to restart the webserver.<br> | Create a .htaccess file in the web catalog you want to password protect: | ||
<pre>/etc/init.d/apache2 restart</pre> | <pre>nano /home/web/protectedfiles/.htaccess</pre> | ||
(Where protectedfiles is the catalog you will protect in this example.) | |||
Create a .htaccess file in the web catalog you want to password protect: | |||
<pre> | |||
nano /home/web/protectedfiles/.htaccess</pre> | |||
(Where protectedfiles is the catalog you will protect in this example.) | |||
A "standard" .htaccessfile could look something like: | A "standard" .htaccessfile could look something like: | ||
<pre> | <pre>AuthType Basic | ||
AuthType Basic | |||
AuthName "Password Required" | AuthName "Password Required" | ||
AuthUserFile /etc/.passwords/.htpasswd | AuthUserFile /etc/.passwords/.htpasswd | ||
Require user user1</pre> | Require user user1</pre> | ||
(Where user1 is the username you log in with in this example.) | (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. | |||
To create the file containing the passwords for the users, type:<br> | Create a catalog to place your password file in:<br> | ||
<pre>htpasswd -c /etc/.passwords/.htpasswd user1</pre> | <pre>mkdir /etc/.passwords</pre> | ||
You now have to enter a password for the user "user1". | To create the file containing the passwords for the users, type:<br> | ||
<pre>htpasswd -c /etc/.passwords/.htpasswd user1</pre> | |||
You now have to enter a password for the user "user1". | |||
To add more users in the .passwords file, leave out the -c parameter:<br> | To add more users in the .passwords file, leave out the -c parameter:<br> | ||
<pre>htpasswd /etc/.passwords/.htpasswd user2</pre> | <pre>htpasswd /etc/.passwords/.htpasswd user2</pre> | ||
You now have to enter a password for the user "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.<br> | 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.<br> |
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.