How to authenticate web access to perticular user?
Step1 : Check if the apache package is installed or not. If it’s not installed install it.
#rpm -qa | grep httpd
#yum install httpd
Step2 : Create DNS CNAME entry for this virtual host as auth.linuxnix.com which should point to our server name server.linuxnix.com
Step2a : Create a home direcotry for our virtual host and index.html file
Step3 : Create and configure user names to whom we should give access to this site. For this we have to create user name and passwords virtually.
Step3(a) : Create an empty file in /etc/httpd
Step3(b) : Create usernames who require access to this site..
#htpasswd -mc /etc/httpd/passwd username
Then it will ask for passwd for this new user
Let me explain about two steps.
/etc/httpd/passwd file contains all the user names with encrypted passwords.
htpasswd is the command to create the new users
-m =>MD5 encryption
-c => Create a password file if it’s not there
Once the above users are create we have to create .htaccess file in /websites/auth folder. So that our site will be accessed through authentication.
AuthName “Testing for Authentication”
Save the file and exit
Step4 : Configure virtual host now in our httpd.conf file which is located at /etc/httpd/conf/
Step4(a) : Specify ServerName as server.linuxnix.com in httpd.conf file
Step4(b) : Specify NameVirtualHost
Step4(c) : Create index.html in /websites/auth/ folder and edit something in that file
Save and exit the file
Step4(d) : Now create a virtual host entry.
Let me explain new entries in this virtualhost
Directory /websites/auth => This indicate where should the authentication should start. Its /websites/auth so when ever user tries to access this folder /websites/auth it should ask for username and password.
AllowOverride Authconfing => This specifies user require to enter username/password when entering this site.
Save and exit the file
Step5 : Check for the syntax errors in the httpd.conf file before restarting the apache service.
#httpd -k graceful
Step6 : Now start the service and then add it to booting scripts so that it will start automatically at every boot of the system
#service httpd restart
#chkconfig httpd on
step7 : Now try to access http://auth.linuxnix.com you will be prompted to enter username and password.
Latest posts by Surendra Anne (see all)
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018