Här kommer ett långt inlägg!
(Från utmärkta O´Reilly-sidan jag hänvisade till i några trådar hägre upp)
Har just provat och det funkade. Filen ".htaccess" läggs i den mapp du vill lösenordsskydda, även i mitt fall phpMyAdmin.
Här kommer urklippet:
Password Authentication
One of the most common uses of .htaccess files is password-protecting a directory. When protected directories are accessed, a visitor´s browser will prompt for a username and password. If the visitor authenticates correctly, they´re allowed in -- if not, an error 401 is triggered, and the visitor is denied.
So yes, Dan from Marketing, we did get your email (and its annoying and frequent follow-ups), and yes, we´re going to password protect the "super secret ad campaign" directory you´ve been working oh-so-hard on (snicker, snicker, reese´s pieces).
To start the process, we´re first going to create the user database. This database will contain all the usernames and passwords that will be authenticated against -- they´re not keyed to any specific directory, so you could use one database for three hundred users spread across two dozen directories. To create the database, get into your Terminal, and gaze blurry eyed at the command below:
htpasswd -c /Library/WebServer/.htpasswd dan
It´s nice and innocent, right? htpasswd is the name of the utility that creates and modifies this user database of ours. The -c flag says "if this database doesn´t exist, create it." /Library/WebServer/.htpasswd is the full path to our database file, and you´ll want to take special notice that it´s outside Apache´s DocumentRoot (which, in OS X, is defined as /Library/WebServer/Documents). Sticking the file outside the DocumentRoot ensures that no one can view this database from the Web. Finally, dan is the user that you want to add to the database. An output of this command is below:
htpasswd -c /Library/WebServer/.htpasswd dan
New password: ********
Re-type new password: ********
Adding password for user dan
You´ll want to make sure that when you add new users to an existing database file that you do not use the -c flag. Doing so will overwrite your existing file with a brand new one. Not so good, bub. Adding a user is a simple matter (note the lack of the -c flag):
htpasswd /Library/WebServer/.htpasswd mishka
New password: *********
Re-type new password: *********
Adding password for user mishka
If you look at /Library/WebServer/.htpasswd, you´ll see the added users:
less /Library/WebServer/.htpasswd
dan:Vcv7xTIIW6g7U
mishka:3c4T6IdfWweU
Next, it´s really just a matter of telling Apache what directory we want to secure. Open (or create) your .htaccess file, and add the following:
AuthName "Uber Goober Ad Campaign"
AuthType Basic
AuthUserFile /Library/WebServer/.htpasswd
require valid-user
AuthName will be shown as the title or description of the password box that a visitor´s browser will show, and in Apache lingo, this is called a "realm". AuthType is set to the standard "Basic" authentication (a "Digest" authentication exists, but is outside the scope of this article). AuthUserFile should be self-explanatory.
The require line affords some discussion. With it, you can tell Apache to allow any user in the AuthUserFile access (as we´ve done above), or you can tell Apache to allow only certain people. In the example below, only the users "dan" and "mishka" can authenticate to realms with the name "Uber Goober Ad Campaign." Any other users in the AuthUserFile will be denied:
require user dan mishka
Users can also be defined by groups -- for example, you could place "dan," "mishka," and "morbus" into a group called "Marketing," and "themadman," "ashcraft," and "sprocket" into a group called "Design." From there, you could restrict access by group instead of username. For these configurations and more about Digest authentication, refer to Apache´s Authentication, Authorization, and Access Control docs.
___
Ja. Lättare att besöka sidan där Terminalkommandona är färgkodade.
[ 28 Maj 2002, 22:02: Meddelandet ändrat av: spacemanspiff ]