Password-protect a folder (Directory Privacy) and block IP addresses (IP Blocker) in cPanel
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.
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 examplepublic_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
.htaccessfile. If you have edited.htaccessby hand before, make a copy of the file (see B44, Section 2).
3. Password-protect a folder: Directory Privacy
- In cPanel, open Directory Privacy in the Files section.
- Click folder names to go to where the folder you want to protect is (for example
public_htmlfirst, thengyro-test). - Click Edit on the row of the folder you want to protect.
- Under Security Settings, tick Password protect this directory.
- 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. - Under Create User, type a Username.
- 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.
- Press Save at the bottom of the section. The user appears in the Authorized Users list.
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:
- In File Manager, go to the protected folder (if hidden files aren't shown, use Settings → Show Hidden Files (dotfiles)).
- Select the folder's
.htaccessfile and click Edit. - Below the section managed by cPanel (lines marked
cp:ppd), add this line and press Save Changes:
ErrorDocument 401 default
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
- Open IP Blocker in the Security section.
- 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
- Single address:
- 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.
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).
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:
- Open a private browser window and enter the protected folder's address (for example
https://ornekfirma.com/gyro-test/gizli/). - A window asking for a username and password should appear.
- With a wrong password the page shouldn't open; with the right password the folder's content should appear.
For IP Blocker:
- 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.
- 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.
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.
8. Related guides
- 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
Thanks for your feedback!
