Authentication apache using .htaccess on linux |In this
article we learn how to configure basic authentication with apache using
.htaccess on centos server.
Apache is
most popular web server all over the world. To enhance the security of apache
by configuring website with password
authentication which is prevent malicious users from accessing the website.
Allow .htaccess authentication on apache
By default .htaccess
is not enable on apache configuration file. We need to configure it .To
configure it we need to go http default configuration file and search “<Directory
"/var/www/html">”section and under this section we
need to change the From AllowOverride
none to AllowOverride AuthConfig.
Create password file using htpasswd on apache
We need to
create a hidden htpasswd file which is used to store the credential of user
which is necessary to login the website. We are creating this hidden file under
“/etc/httpd” directory.
To create
the .htpasswd file we need to execute the below command.
#htpasswd
-c /etc/httpd/.htpasswd testuser
After that
put the password and confirm it ,it will stored into the hidden file.
The content
of this file as below.
[root@localhost ~]#
cat /etc/httpd/.htpasswd
testuser:$apr1$GQ7aRO.O$NCFWjQEqLUkUfQN7JwdGP1
Now we need to change the permission
and ownership of the hidden file to read it by apache user.To do this we
execute the below command.
#chown
apache:apache /etc/httpd/.htpasswd
#chmod 660 /etc/httpd/.htpasswd
#chmod 660 /etc/httpd/.htpasswd
Now we
create .htaccess file inside the web directory which is “/var/www/html” and add
these below lines inside the files to configure password authentication on
apache.
AuthType
Basic
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user
After that we need to restart the apache service using the below command.
#systemctl
restart httpd
After that
when we are using the web url through browser we will get the authentication
promt as below.
How to configure Basic Authentication with Apache using .htaccess on CentOS 7 server step by step guide |
0 comments:
Post a Comment