I needed to lock down a couple directories on this server using Basic Authentication in Apache… in case you’ve ever wanted too, or someday will need too:
1) Add the username to the password file using the htpasswd module:
# htpasswd /etc/httpd/users username
where ‘/etc/httpd/users’ is the name of the file you want your users/passwords stored and ‘username’ is the username you want to add. It’ll ask you for the password, and then again before adding the user to the file. If the file doesn’t exist, usr the -c flag to create the file:
# htpasswd -c /etc/httpd/users username
2) Then add a .htaccess file in the directory you wan to secure that contains this:
AuthName “username”
AuthType Basic
AuthUserFile /etc/httpd/users
require user username
where ‘/etc/httpd/users/’ is the name your passwd file and ‘username’ is the name of the user you want to allow in this directory.