Skip to content
0850 554 5439 [email protected]

What do you need help with?

Search the guides and tutorials, or browse the categories.

Password-protect a folder (Directory Privacy) and block IP addresses (IP Blocker) in cPanel

Shared Hosting 37 views Step-by-step guide Last verified: Markdown
What you will learnHow to put a folder behind a username and password with Directory Privacy, keep malicious IP addresses away from your site with IP Blocker, and check that both protections work.
Time10 minutes

1. What does each tool do?

cPanel has two simple tools that restrict access to your site:

  • Directory Privacy: asks anyone who opens a folder for a username and password in the browser. Suitable for a test site that isn't ready yet, files for a specific client, or an admin page.
  • IP Blocker: closes the whole site to the IP addresses you add to the list. When these addresses try to open your site, they see 403 Forbidden.
The difference between Directory Privacy and IP Blocker: one puts a password on a folder, the other closes the whole site to specific IP addresses.
Info

Your cPanel login password and the users you create in Directory Privacy are separate. A directory user can open only that folder and cannot log in to cPanel.

2. Before you start

  • Know where the folder you want to protect is inside public_html (for example public_html/gyro-test/gizli). Protection also applies to all its subfolders.
  • Check the address you want to block. To find your own IP address, open a "what is my IP" page from the office or home, and make sure you don't block that address.
  • Both tools add lines to an .htaccess file. If you have edited .htaccess by hand before, make a copy of the file (see B44, Section 2).

3. Password-protect a folder: Directory Privacy

  1. In cPanel, open Directory Privacy in the Files section.
  2. Click folder names to go to where the folder you want to protect is (for example public_html first, then gyro-test).
  3. Click Edit on the row of the folder you want to protect.
Files → Directory Privacy: click a folder name to go inside it and press Edit on the row of the folder you want to protect. Protected folders show a lock icon.
  1. Under Security Settings, tick Password protect this directory.
  2. In Enter a name for the protected directory:, type a name that will appear in the login window (for example Gyro Proje Private Area) and press the Save button right below it.
  3. Under Create User, type a Username.
  4. Enter the password in New Password and Confirm Password. For a strong password you can use Password Generator; save the generated password in a password manager.
  5. Press Save at the bottom of the section. The user appears in the Authorized Users list.
Tick the protection box, give it a name and press Save; then in Create User enter a username and a strong password (Password Generator) and save.

To open the folder to several people, create a separate user for each. To remove someone's access, choose the user in Authorized Users and press Delete User. To change a password, add the same username again with the new password.

If you use WordPress: a password window instead of 404

If WordPress is installed at your site's root, opening the protected folder may show WordPress's 404 page instead of the password window. We saw exactly this on our test account: to ask for the password, the server looks for an error page, that request falls through to WordPress, and the browser gets a 404.

The fix:

  1. In File Manager, go to the protected folder (if hidden files aren't shown, use Settings → Show Hidden Files (dotfiles)).
  2. Select the folder's .htaccess file and click Edit.
  3. Below the section managed by cPanel (lines marked cp:ppd), add this line and press Save Changes:
apache
ErrorDocument 401 default
On WordPress sites, if you see a 404 instead of the password window, add the ErrorDocument 401 default line to the protected folder's .htaccess, outside the cPanel section.
Warning

Don't edit the inside of the section that starts with # Section managed by cPanel by hand; always change settings from the Directory Privacy screen.

4. Stop an attacking address: IP Blocker

  1. Open IP Blocker in the Security section.
  2. Type the address you want to block in IP Address or Domain. Accepted formats:
    • Single address: 203.0.113.10
    • Range: 203.0.113.10-203.0.113.40
    • CIDR: 203.0.113.64/27
  3. Press Add.
Security → IP Blocker: type the address to block as a single IP, a range or in CIDR format and press Add.

The addresses you add are listed in the Currently-Blocked IP Addresses table with their beginning and ending IPs. To remove a block, click Delete on its row.

Blocked addresses appear in the table with their beginning and ending IPs. To remove a block, click Delete on its row.

To find which address to block, look in the Visitors or Raw Access logs for addresses that send many requests in a short time or keep trying your login page (see B50).

Warning

Don't block search engine bots; your site will drop out of search results. If there is a CDN or proxy service in front of your site, the server may see that service's address instead of the visitor's; blocking such an address stops all visitors. In that case, block the address in the proxy service's own panel.

5. Check that it works

For Directory Privacy:

  1. Open a private browser window and enter the protected folder's address (for example https://ornekfirma.com/gyro-test/gizli/).
  2. A window asking for a username and password should appear.
  3. With a wrong password the page shouldn't open; with the right password the folder's content should appear.

For IP Blocker:

  1. Since you can't test from the blocked address, open the site from your own address; it should open normally. If it doesn't and you see 403, you may have blocked your own address by mistake.
  2. If the block works, requests from the blocked address appear as 403 on the Visitors and Errors screens.

6. Symptom → cause → fix

Symptom Likely cause Fix
404 instead of a password window on the protected folder WordPress catches the server's 401 page Add ErrorDocument 401 default to the folder's .htaccess (Section 3)
I type the right password but the window keeps coming back Wrong username or password, upper/lower case Add the user again with the same name and a new password
I can't open my own site, I see 403 Your own IP, or a range containing it, is blocked Log in to cPanel from another connection (e.g. mobile data) and Delete the row; for other causes of 403 see B09
The blocked address keeps getting in The attacker changes addresses, or the site is behind a proxy Block the range in CIDR form; if you use a proxy, block it there
After blocking, every visitor gets 403 A very wide range or a proxy address was blocked Delete that row from the table
Protection also closed a subfolder I didn't mean to Protection applies to subfolders Move the protection to a lower-level folder

7. Frequently asked questions

Can I use Directory Privacy to protect the WordPress admin (wp-admin)?

Yes; when you protect the wp-admin folder, this password is asked before the admin login as well. Some plugins use wp-admin/admin-ajax.php for visitors, so test your site's features after adding the protection.

How do I remove the protection?

In Directory Privacy, click Edit on the folder's row, untick Password protect this directory. and press Save.

Does IP Blocker also block email or FTP?

No. IP Blocker only stops requests to your website; it doesn't affect email or FTP access.

Can I block a whole country?

IP Blocker works with single addresses and ranges; managing all of a country's addresses here isn't practical. If the problem comes from a few specific addresses, block only those.

How quickly does a block take effect?

As soon as you press Add. The rule is written to public_html/.htaccess, so it applies to the next request.

Did you know?

Our hosting plans also run the Imunify360 security layer on the server side; it blocks known attack patterns and malicious files without you having to do anything. IP Blocker is an extra lock you add by hand, specific to your own site.

  • B09 — My site returns 403 Forbidden
  • B42 — 503/508 "Resource Limit Reached": resource limits
  • B44 — Redirects with .htaccess: www, HTTPS and 301
  • B46 — Two-factor authentication and account security in cPanel
  • B50 — Visitor statistics and logs
Was this helpful?

Thanks for your feedback!

Still Need Help?

The support team is here around the clock for anything you can't find in the knowledge base.