How to authenticate web access to perticular user?
Ans :
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
#mkdir /websites/auth
#vi /websites/auth/index.html
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
#touch /etc/httpd/passwd
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
Password:******
Retype:*******
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.
#vi /websites/auth/.htaccess
AuthName “Testing for Authentication”
AuthType Basic
AuthUserFile “/etc/httpd/passwd”
require valid-user
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
ServerName server.linuxnix.com
Step4(b) : Specify NameVirtualHost
NameVirtualHost server.linuxnix.com
Step4(c) : Create index.html in /websites/auth/ folder and edit something in that file
#vi /websites/auth/index.html
Save and exit the file
Step4(d) : Now create a virtual host entry.
<VirtualHost 192.168.0.1>
ServerName auth.linuxnix.com
<Directory /websites/auth>
AllowOverride Authconfig
</Directory>
DocumentRoot /websites/auth/
DirectoryIndex index.html
</VirtualHost>
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 -t
or
#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)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - 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