htaccess , htpasswd and error 401
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, authentication, htpasswd, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :I have a problem with htpasswd.
I get an error in error.log apache2
user admin: authentication failure for "/": Password Mismatch
Content of my htaccess file:
# Set Access Restrictions
AuthType Basic
AuthName "admin"
AuthUserFile ".htpasswd"
require valid-user
and content of my htpasswd
admin:xxxxx
From your comment I take it that you just created a plain text password. This will not work for Apache, as Apache expects the password in .htpasswd to be hashed by the MD5 algorithm.
There are several tools available online for generating .htpasswd files, but the easiest might be the one that comes with Apache, it's called htpasswd. On RHEL (Fedora, Red Hat, CentOS) systems you'll need the httpd-tools package (yum install httpd-tools). On Ubuntu systems it's in the apache2-utils package (apt-get install apache2-utils). If you're using XAMPP on Windows it's in the folder xamppapachebin.
To use htpasswd with the .htaccess file you've already got configured, you'd simply do htpasswd /protected/.htpasswd user and then type in your desired password (twice) when prompted. It will then generate your .htpasswd file in the /protected/ directory.
Make sure that you are including the entire path for AuthUserFile. I would suggest that you create a protected directory instead of doing this on the root directory. I made sure and tested these configurations to ensure that they worked.
File Locations
/protected/.htaccess
/protected/.htpasswd
.htaccess File
AuthType Basic
AuthName "restricted area"
AuthUserFile /protected/.htpasswd
require valid-user
. htpasswd File
user:password
Make sure that the password is MD5'd, here is a tool.
Finally, I have not hash a password to md5 .... I've used notepad ++ and I put the password in simple character
I followed this tutorial with the linux command for create file htaccess
now my content of my htpasswd :
admin:$apr1$Oy4JMDb0$yb00PbzV9mrq07lPivrzL1

Comments
Post a Comment