Password protecting directory

Web hosting discussion, programming, and shared and dedicated servers.
4 posts Page 1 of 1
by btwyx » Sun Aug 06, 2023 12:08 pm
I've tried several times and failed to get password protection to work. I've read lots of forum post here about how to get it to work, and other general stuff, but nothing helps.

When I set up an .htaccess file, I'll get an ugly authentication dialog in Safari, but whatever I enter it always pops up again. It's never satisfied. If I hit the cancel button, it gives an "Authorization Required" error.

A lot of forum posts are about the correct path for AuthUserFile, so what is the correct path. It seemed to change a while back, and is different than you get with pwd in the shell.

Any other thoughts to get this to work?
by joemuller » Mon Aug 07, 2023 5:27 pm
Hi, you'll need a couple things to make password-protecting a directory work:
1.) A .htaccess file in the directory that you want to protect (this will apply to that directory and any files/folders inside of it) *
2.) A .htpasswd file in that same directory *

The .htaccess file will need a section that looks something like this:

Code: Select all

AuthType Basic
AuthName "Password Required"
AuthUserFile .htpasswd
Require valid-user
Then you'll need a .htpasswd file in the same directory - these can be generated/modified using the htpasswd utility on shell.sonic.net or any number of online generators, and will look something like this:

Code: Select all

ausername:$passwordhashgoeshere
busername:$anotherpasswordhash
I suspect that your .htpasswd file is somewhere outside of the hosting directory for your site, so that's why it's not working. (See the 'gotcha' below. Hopefully the above info should be enough to fix any issues, but let me know if it doesn't work.

-- Joe M

* A quick 'gotcha' is that these cannot cross into another website root. Often, if you have multiple websites, each will live in its own directory under public_html (or /var/www/html/, etc) - those sites cannot access things in directories 'above' them, so the highest place your .htaccess and .htpasswd files can go is where your main Index page resides.
I'm a proud employee of Sonic.net! :-)
by btwyx » Mon Aug 07, 2023 6:10 pm
That's pretty much what I've done the several times already, and the result is exactly the same.

Just to make sure I copied all your stuff, and still exactly the same. The .htaccess and .htpassword file are all in the same directory.
by btwyx » Wed Aug 09, 2023 10:07 am
I got a private message about this, but the forum software isn't letting me reply to it.
4 posts Page 1 of 1

Who is online

In total there are 16 users online :: 0 registered, 0 hidden and 16 guests (based on users active over the past 5 minutes)
Most users ever online was 999 on Mon May 10, 2021 1:02 am

Users browsing this forum: No registered users and 16 guests