Tuesday, August 6, 2013

HOW TO GIVE USER-BASED AUTHENTICATION TO WEBSITE IN APACHE SERVER



The htpasswd is the command used to give password to the various users who try to access a particular webpage in Apache 
Web Server.The following commands are executed to provide the user-based authentication:

 # htpasswd -cm /etc/httpd/conf/.htpasswd User_Name

Change the directory to http configuration file where the above file (.htpasswd) is created.
 # cd /etc/httpd/conf

Check the content of the file created using following command which will  show the encrpyted password:
 # ls -a

the above command shows the hidden files.

Next create the access file in the directory where webpages are  placed as follows:
 # vim /var/www/html/WebPage_Dir/.htaccess

Make the following entries in the above file :
 :i
 AuthType Basic  #AuthType directive selects that method that is used to authenticate the user. The most common method is 
Basic AuthName “Server Authentication”    #This directive sets the Realm to be used in authentication which is presentd to user 
as part of password dialog box as well as client uses it to determine what password to send for given authenticated area.
 AuthUserFile  /etc/httpd/conf/.htpasswd       #AuthUserFile directive sets the name of a textual file containing the list of users 
and passwords for user authentication.
 Require valid-user           #Grant access to all successfully authenticated users.
 :wq

Finally, to implement the changes make the following changes in th configuration file of apache server which is 
/etc/http/conf/httpd.conf:
 # vim /etc/httpd/conf/httpd.conf
 :i
 <directory /var/www/html/WePage_Dir>
  AllowOverride Authconfig
 </directory>

Now restart the service daemon and access the site from the client-end.
 # service httpd restart

0 comments:

Post a Comment