If you don't want to use a server-side language (like PHP or ASP or something like that), you can use .htaccess files.
Run 'vi /protected/directory/.htaccess' (you change it to meet your needs).
Put this into the file:
Code:
AuthName "Protected Files"
AuthType Basic
AuthUserFile /protected/directory/.htpasswd
Require valid-user
Then use the command 'htpasswd -bc /protected/directory/.htpasswd username password'
For example, if you wanted to protect the folder /var/www/protected_dir with username 'admin' and password 'foo' you could use:
/var/www/protected_dir/.htaccess:
Code:
AuthName "Protected Files"
AuthType Basic
AuthUserFile /var/www/protected_dir/.htpasswd
Require valid-user
htpasswd -bc /var/www/protected_dir/.htpasswd admin foo
If you go into
http://localhost/protected_dir/ (assuming that /var/www is Apache's document root) you should get a prompt for a username and password.
If it doesn't work, open up httpd.conf and search for 'AllowOverride' in your server's document directory. It should say at least 'AuthConfig'; 'All' is fine.
There are countless guides on Google to how you can enhance this, incuding Apache's own at
http://httpd.apache.org/docs/howto/htaccess.html