1. Websta Hosting
Backups & Security

How to Password Protect a Directory

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

  1. Log in to DirectAdmin → File Manager.
  2. Navigate to the directory you want to protect.
  3. Click Password Protect Directory (if available in your DA version).
  4. Enter a username and password.
  5. Click Save.

Method 2: Manual .htaccess

  1. Create /home/yourusername/.htpasswd using SSH:
htpasswd -c ~/.htpasswd protecteduser

Enter your desired password when prompted.

  1. Create or edit .htaccess in 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.

Still need help?

If this article didn't answer your question, our support team can help.

Contact support
All articles More in Backups & Security