Hi
I used following command and set .htpasswd user and password. but i got task failed.
sudo htpasswd -c /etc/httpd/.htpasswd username
Can you tell me what mistake i made.
Hi
I used following command and set .htpasswd user and password. but i got task failed.
sudo htpasswd -c /etc/httpd/.htpasswd username
Can you tell me what mistake i made.
@harikrishnan can you please share the error which you are getting. meanwhile there are no issue with command.
Hi @harikrishnan I guess you created the file correctly but , you did not set proper permissions for the file , the file owner should be apache user and it should be able to read the file. Also did you start the httpd service before finishing the task? Try this when the task is assigned again.
Sure. Thanks for update
You need to validate that under Directory section for βvar/www/html/β and AllowOverride to All
#sudo vi /etc/httpd/conf/httpd.conf
Also you create .htaccess on new directory
you can test your configuration is correct by
curl -u rose http://127.0.0.1:8080/itadmin/index.html
You will be prompt for the password
In jumphost:
thor@jump_host /$ scp /tmp/index.html tony@stapp01:/tmp
scp /tmp/index.html steve@stapp02:~
cd /var/www/html/
mkdir finance
cd finance
cp /tmp/index.html .
sudo htpasswd -c /var/www/html/finance/.htpasswd rose
chown apache:apache /var/www/html/finance/.htpasswd
chmod 640 /var/www/html/finance/.htpasswd
Also created .htaccess under /var/www/html/finance/ :
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /var/www/html/finance/.htpasswd
Require user rose
systemctl restart httpd
systemctl status httpd
To Validate :
curl -u rose http://127.0.0.1:8080/finance/index.html
curl -u rose http://172.16.238.10:8080/finance/index.html
refer : https://www.tecmint.com/password-protect-apache-web-directories-using-htaccess/
this is worked for me.