Authentication & Access Control in Apache
From the Apache cheat sheet ยท Security & Access Control ยท verified Jul 2026
Authentication & Access Control
Password-protect directories and restrict access by IP
apacheconf
# Password-protect a directory
<Directory /var/www/admin>
AuthType Basic
AuthName "Admin Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
# Create password file
# htpasswd -c /etc/apache2/.htpasswd admin๐ก htpasswd -c creates the file โ omit -c when adding users to an existing file or it overwrites
โก Options -Indexes prevents directory listing โ always disable this in production
๐ Block .env, .git, and backup files with FilesMatch โ they should never be web-accessible
๐ข Combine Require valid-user + Require ip inside <RequireAll> for defense in depth
authhtpasswdaccess-control