How to Password Protect a Directory
Password protection restricts access to a directory — useful for staging sites, admin areas, or private content.
Method 1: DirectAdmin Control Panel
- Log in to DirectAdmin → File Manager.
- Navigate to the directory you want to protect.
- Click Password Protect Directory (if available in your DA version).
- Enter a username and password.
- Click Save.
Method 2: Manual .htaccess
- Create
/home/yourusername/.htpasswdusing SSH:
htpasswd -c ~/.htpasswd protecteduser
Enter your desired password when prompted.
- Create or edit
.htaccessin the directory you want to protect:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/yourusername/.htpasswd
Require valid-user
Allowing Specific IPs to Bypass Auth
AuthType Basic
AuthName "Restricted"
AuthUserFile /home/yourusername/.htpasswd
Require valid-user
Satisfy Any
Order deny,allow
Deny from all
Allow from 203.0.113.10
This allows your office IP without a password while requiring auth from everywhere else.