Having a directory under Basic Authentication is really easy when using the Apache2 web server.
You just have to define a file with users, passwords and groups, and place some lines in the .htaccess file.
The first goal can be achieved with the htpasswd utility, such as
htpasswd [-s|-m|-d|-p] [-c] <file> <username>
where the first group of options specify the way to store passwords ( -s for sha, -m for md5, -d for crypt(), -p for plaintext ), and -c create a new file. Be careful because the -c overwrite any existing file. If you wish just to add a user to an existing file, care to omit the -c . You can also specify group of users in a groupfile, man htpasswd should help.
Then you need to place an .htaccess file in the folder you want to protect, with something like
AuthType Basic
AuthName "Your authentication prompt message"
AuthUserFile /path/to/user/auth/file
AuthGroupFile /path/to/group/auth/file
Require user username
Use absolute paths for the authentication file or relative paths that are resolved from /etc/apache2.
Here you go, restart the apache web server and your basic http authentication is ready.
Just remember that this is plain-text over the network, and that it’s a pain to maintain, so you should use this only for really poor stuffs with few, unlikely to change users or groups, and most likely over SSL.