General

How to Password Protect a Directory

Updated November 2026 14,937 views 3 min read
General | Updated November 2026

You can password-protect any directory on your website so that visitors must enter a username and password to access it. This is useful for staging areas, private file downloads, admin sections, or client portals. cPanel has a built-in tool that makes it easy, no manual .htaccess editing required.

01. Password Protect via cPanel

  1. Log into cPanel > click Directory Privacy (in the Files section)
  2. Navigate to the directory you want to protect and click its name
  3. Check "Password protect this directory"
  4. Enter a name for the protected directory (this appears in the login prompt visitors see)
  5. Click Save
  6. Create an authorized user - enter a username and password, then click "Add or modify the authorized user"

You can add multiple users if several people need access. Each gets their own username and password.

Tip

Password protection works on any directory, including public_html itself (protects your entire site), subdirectories, or addon domain directories. The login prompt appears before any content is served, so even images and CSS in the protected directory are hidden.

02. Manual .htaccess Method

If you prefer manual control, create two files in the directory you want to protect:

.htaccess

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/yourusername/.htpasswds/public_html/protected/passwd
Require valid-user

.htpasswd

Generate the password hash using cPanel > Terminal:

htpasswd -c /home/yourusername/.htpasswds/public_html/protected/passwd username

The AuthUserFile path must be the full server path to the password file, not a relative path. Place the password file outside of public_html if possible so it can't be downloaded by visitors.

For more .htaccess techniques, see our Complete .htaccess Guide.

03. Removing Password Protection

To remove protection, go back to cPanel > Directory Privacy, navigate to the folder, and uncheck "Password protect this directory." Click Save. The directory is immediately public again.

If you used the manual method, delete the AuthType, AuthName, AuthUserFile, and Require lines from the .htaccess file.

Need Help With Access Control?

If you need more advanced access control (IP-based restrictions, single sign-on, etc.), open a ticket and describe your requirements.

Open a Support Ticket

Frequently Asked Questions

How do I password-protect a directory in cPanel?

Use the Directory Privacy tool in cPanel, choose the folder, enable protection, and create a username and password. cPanel writes the necessary .htaccess and password files for you, so no manual editing is needed.

Can I password-protect a folder without cPanel?

Yes. You can create an .htaccess file with AuthType and require-valid-user directives plus an .htpasswd file of credentials. The cPanel Directory Privacy tool does exactly this for you, which is simpler and less error-prone.

What is directory password protection useful for?

It is ideal for staging areas, private downloads, admin sections, and client portals, where you want a login prompt before anyone can view the folder. It adds an access gate on top of whatever the application itself does.

How do I remove password protection from a directory?

In the cPanel Directory Privacy tool, open the folder and disable protection, then remove any users you added. If you set it up manually, delete or edit the relevant .htaccess and .htpasswd entries.

Quick Recap

  1. cPanel > Directory Privacy - easiest method, no code needed
  2. Select directory, enable protection, create user - three steps
  3. Multiple users supported - each with their own credentials
  4. Works on any directory - including your entire site
  5. Remove by unchecking - in Directory Privacy settings

Last updated November 2026 · Browse all General articles

Share: X in Reddit f Email
  • 444 Users Found This Useful

Was this answer helpful?

Related Articles

Setting up Zend Framework

Note: This article covers the Zend Framework, which has reached end of life (its successor is...

Cloudflare Error 521: Web Server Is Down

Errors & Troubleshooting | Updated November 2026 Cloudflare Error 521: Web Server Is Down...

How do I parse html files as shtml?

General | Updated November 2026 Server Side Includes (SSI) let you pull content from one file...

NodeJS Brotli RCE Vulnerability CVE-2026-111497 Node2Shell - Patch Status

Server Security | Updated October 2026 Ultra Web Hosting servers are fully patched against...

Why is the server load status red?

General | Updated November 2026 The "Server Status" indicator on the right sidebar of cPanel...



Save 30% on web hosting - Use coupon code Hosting30