Password-Protecting Directories

6 views Security & SSL

Setting Up .htpasswd Protection in DirectAdmin

Password-protecting a directory adds a layer of security by requiring a username and password before anyone can access the files in that folder. This is commonly used for staging sites, admin areas, or sensitive content.

Using DirectAdmin's Built-in Tool

  1. Log in to DirectAdmin and navigate to Advanced Features → Password Protected Directories (sometimes listed under System Info & Files).
  2. Click Add New Protected Directory or Protect a Directory.
  3. Browse and select the directory you want to protect, or type the path relative to your home directory (e.g., /domains/example.com/public_html/admin).
  4. Enter a username and password for accessing the directory.
  5. Optionally set a name for the protected area (this appears in the login prompt).
  6. Click Save or Protect.

Manual Setup via .htaccess and .htpasswd

You can also set this up manually using the File Manager or FTP.

Step 1: Create a .htpasswd file outside the web-accessible directory (e.g., in /home/username/.htpasswd):

username:$apr1$xyz$HashedPasswordHere

Generate the hashed password using the command line or an online htpasswd generator tool.

Step 2: Create or edit the .htaccess file inside the directory you want to protect:

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/username/.htpasswd
Require valid-user
Tip: Place the .htpasswd file outside your public_html directory so it cannot be downloaded by visitors. The AuthUserFile path must be the full absolute server path.

Managing Users

To add additional users, return to the Password Protected Directories section in DirectAdmin and add new username/password combinations. Each user will have their own credentials. To revoke access, simply remove the user entry.

Removing Protection

To remove password protection, go back to the protected directories list, select the directory, and click Remove Protection. This deletes the relevant .htaccess rules and .htpasswd entries.

Need More Help?

Can't find what you're looking for? Our support team is ready to help.

Contact Support
Hi there! How can we help?
Chat with us