Htaccess: Difference between revisions

From Redbrick Wiki
Jump to navigation Jump to search
mNo edit summary
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
.htaccess
'''.htaccess'''


[ Author : Declan McMullen (skyhawk) : 2003] [ Updated : John Doyle (art_wolf) : June 2004 ]
Redbrick's Webserver, apache, allows users to password protected certain sections of their websites via a method known as "htaccess".


RedBricks WebServer (apache) allows user to password protected certain section of their website via a method known as htaccess.
This is done by creating a password file for authorized users and a .htaccess file in the directory which you would like to protect.


It is accomplished by creating a password file for authorized users and a .htaccess file in the directory which you would like to protect.
== Setting a password ==
Password Setting


The password file comes first
The password file comes first. To create a htaccess password file and assign an authorized user to it type:


To create a htaccess password file and assign an authorized user to it type:
htpasswd -c ~/passwd username


htpasswd -c ~/passwd username
You can give the password file any name you like, just substitute the name you choose for passwd above. In this tutorial, references to passwd mean your password file. The value of username is the name of the user that you wish to grant access to. After running this command, you will be prompted to enter a password. This is the password that will be used by that user to gain access.


You can give the password file any name you like just substitute the name you choose for passwd above. In the tutorial references to passwd mean your password file
To allow the server access to query this file you will need to change its file permissions. Type the following into your terminal:


The value of username is the name of the user that you which to grant access to. You will be prompted to enter a password that will be used to grant access to that user. Follow the instructions and when completed that is your password file created
chmod 755 ~/passwd


To allow the server access to query this file you need to change its file permissions.
== Directory Creation ==
 
Next, you create a directory that will be protected by the password file you just made. For the tutorial, we will call this directory "secret", but you can call it whatever you want.


Type the following into your terminal:
Type the following into your terminal:


chmod 755 ~/passwd
mkdir ~/public_html/secret


That completes the configuring of the password file
Once again the correct permission must be set. Simply type the following into your terminal:
Directory Creation


Next you have to create a directory that will be protected by the password file
chmod 711 ~/public_html/secret


We will call this directory secret but you can call it whatever you wish
Now you're almost done.


Type the following into your terminal:
== .htaccess file ==


mkdir ~/public_html/secret
With the password file and protected directory in place all that remains is the .htaccess file to tie it all together. The .htaccess file is what will tell the Webserver that the directory is password protected and requires authorisation.


Once again the correct permission must be set.Simply type the following into your terminal:
Change to your protected directory by typing:


chmod 711 ~/public_html/secret
cd ~/public_html/secret


Now your almost done.With the password file and protected directory in place all the remains is the .htaccess file to tie it all together
Now type nano .htaccess to open the file in a text editor
.htaccess file


The .htaccess file is what will tell the WebServer that the directory is password protected and requires authorization
Copy and paste the contents of the sample htaccess file into the editor, making the necessary modification to the AuthUserFile line, e.g.
AuthType Basic
AuthName "User Login"
AuthUserFile /home/member/g/gizmo/passwd
require valid-user


Click here for a sample .htaccess file
'''Note:''' keep the name of the file .htaccess - this is an actual file extension recognised by Apache and it must be used.


Change into your protected directory by typing:
Lastly we need to set the permission on the file by typing:


cd ~/public_html/secret
chmod 644 .htaccess


Now type nano .htaccess to open a text editor
== htaccess & pubcookie ==


Copy and paste the contents of the sample htaccess file into the editor, making the necessary modification to the AuthUserFile line , and save in the usual manner. Note do keep the name of the file .htaccess - this is an actual file extension recognised by Apache and it must be used.
You can use your htaccess file with the RedBrick pubcookie system. With this you can restrict access to redbrick members. See [[PubCookie on Redbrick]] for more.


Lastly we need to set the permission on the file by typing:
== Testing ==


chmod 755 .htaccess
To test if the directory is protected correctly, type its url into a browser, eg:
Testing


To test if the directory is protected correctly type its url into a browser eg:
www.redbrick.dcu.ie/~username/secret


redbrick.dcu.ie/~username/secret
If all works correctly you should now be prompted for a username and password to gain access. If you'd like to give access to another user, this is easily done using a similar command syntax to before:


If all works correctly you should now be prompted for a username and password to gain access
htpasswd ~/passwd username


If you wish to give another user access at any time this is easily done using a similiar command syntax to before
You'll be prompted to enter the new password twice as you were before. Once entered, the new user is active immediately and can gain access to the protected directory.


htpasswd ~/passwd username
As always, you can contact [[Helpdesk]] if you have any problems.


You'll be prompted to enter the new password twice as you were before. Once entered the new user is active immediately and can gain access to the protected directory
[[Category:Helpdesk]]

Latest revision as of 16:04, 14 September 2008

.htaccess

Redbrick's Webserver, apache, allows users to password protected certain sections of their websites via a method known as "htaccess".

This is done by creating a password file for authorized users and a .htaccess file in the directory which you would like to protect.

Setting a password

The password file comes first. To create a htaccess password file and assign an authorized user to it type:

htpasswd -c ~/passwd username

You can give the password file any name you like, just substitute the name you choose for passwd above. In this tutorial, references to passwd mean your password file. The value of username is the name of the user that you wish to grant access to. After running this command, you will be prompted to enter a password. This is the password that will be used by that user to gain access.

To allow the server access to query this file you will need to change its file permissions. Type the following into your terminal:

chmod 755 ~/passwd

Directory Creation

Next, you create a directory that will be protected by the password file you just made. For the tutorial, we will call this directory "secret", but you can call it whatever you want.

Type the following into your terminal:

mkdir ~/public_html/secret

Once again the correct permission must be set. Simply type the following into your terminal:

chmod 711 ~/public_html/secret

Now you're almost done.

.htaccess file

With the password file and protected directory in place all that remains is the .htaccess file to tie it all together. The .htaccess file is what will tell the Webserver that the directory is password protected and requires authorisation.

Change to your protected directory by typing:

cd ~/public_html/secret

Now type nano .htaccess to open the file in a text editor

Copy and paste the contents of the sample htaccess file into the editor, making the necessary modification to the AuthUserFile line, e.g.

AuthType Basic
AuthName "User Login"
AuthUserFile /home/member/g/gizmo/passwd
require valid-user

Note: keep the name of the file .htaccess - this is an actual file extension recognised by Apache and it must be used.

Lastly we need to set the permission on the file by typing:

chmod 644 .htaccess

htaccess & pubcookie

You can use your htaccess file with the RedBrick pubcookie system. With this you can restrict access to redbrick members. See PubCookie on Redbrick for more.

Testing

To test if the directory is protected correctly, type its url into a browser, eg:

www.redbrick.dcu.ie/~username/secret

If all works correctly you should now be prompted for a username and password to gain access. If you'd like to give access to another user, this is easily done using a similar command syntax to before:

htpasswd ~/passwd username

You'll be prompted to enter the new password twice as you were before. Once entered, the new user is active immediately and can gain access to the protected directory.

As always, you can contact Helpdesk if you have any problems.