CentOS Linux Server Guide

CentOS Web Server

Authentication in Apache

 

There are 2 authentication method in Apache. There are:-

 

Host based authentication

Host based authentication is regulated using IP address, domain name, host name

 

User based authentication

User based authentication is regulated by username and password of usinf authentication Internet Browser's dialogue box. There are 2 types of authentication method 

  • Basic Authentication

This is the most basic authentication and well supported by many browser. However, authentication sending are in plain text format.  Thus, this is not suitable for untrust network. 

  • Digest Authentication

The authentication information is encrypted via MD5.

Configure Basic Authentication

Step1: Create a directory which intent to restrict access

mkdir /var/www/html/member

 

Step2: Using htpasswd command to create authenticate use, we are using username "basic" here

htpasswd -c /etc/httpd/.htpasswd basic

 

Step3: Enter a password for user

htpasswd -c /etc/httpd/.htpasswd basic
New password:
Re-type new password:
Adding password for user basic

 

Step4: Enter AuthType, AuthName, AuthUserFile

vim /etc/httpd/conf/httpd.conf

 

Add in the following into the httpd.conf file.


<Directory "/var/www/html/member">
AuthType Basic
AuthName "Member Access Directory"
AuthUserFile /etc/httpd/.htpasswd
Require user basic [username,username]
</Directory>
 

 

Step5: Changing ownership of .htpasswd file

chown apache.apache /etc/httpd/.htpasswd basic

 

Step6: Reload Apache web server

service httpd reload

 

Step5: Testing and verify the setting

Accessing the member folder via web

Apache Web Server Authentication Diagloue Box

 

The following show the folder access after successful authentication.

Apache Web Server Sucessful Login Page

 

Configure Digest Authentication

Step1:Create a directory which you want to restrict the access.

mkdir /var/www/html/area51

 

Step2: Using htdigest to create

 htdigest -c /var/www/html/area51/.htdigest 'area51' member

 

Step3: Enter a password for user

Adding password for member in realm area51.
New password:
Re-type new password:
Adding password for member in realm area51.
New password:
Re-type new password:

 

Step4:Add in the following into the httpd.conf file.

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/area51">
AuthType Digest
AuthName "Area51 Member Access Directory"
AuthDigestDomain /area51/
AuthUserFile /etc/httpd/.htdigest
Require user basic
</Directory>
 

 

Step5: Changing ownership of .htpasswd file

chown apache.apache /etc/httpd/.htdigest

 

Step6: Restart the Apache web server

service httpd restart

 

Back to CentOS Apache Web Server



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy