Security for sensitive content on your website is always essential. You’ll likely need security features to restrict access to your site’s confidential files or entire pages. Password protection through cPanel provides a layer of security to give you total control over sections of your website.
This step-by-step guide will help you password-protect a page using cPanel. You can follow the methods outlined to secure and control access to your site pages.
What You Need to Password Protect a Page Using cPanel
You need an active cPanel server and the correct login credentials to password-protect a page. You also need to have a working knowledge of cPanel’s interface and be able to navigate the File Manager.
You may need a text editor (for password protection using .htaccess) and an online .htpasswd generator for an alternative method.
Method 1: Password Protecting a Page with cPanel
This method can password-protect every file within a folder. Password-protecting a page is excellent for safeguarding specific content on your site. You can also deploy this method to password-protect entire file directories to secure whole sections of your website.

Step 1: Log in to cPanel
Open your web browser and type in your domain followed by /cpanel. Next, enter your login credentials (username and password) to enter the cPanel dashboard window.
Step 2: Find and open the directory privacy
Scroll to the Files section in the dashboard. Next, click Directory Privacy (or Password Protect Directories in some versions).
Step 3: Select a directory with a page for protection
Locate the folder with the page you plan to restrict through the Directory Privacy interface. Place the page into a separate folder and rename its directory accordingly. Click on the folder with the page to open its settings.
You can also select the entire directory to password-protect everything, including pages.
Step 4: Enable password protection
Check the box labeled ‘Password Protect this directory.’ Continue by entering the name for your newly-protected directory in the field provided. Next, click ‘Save’ to reveal a confirmation message indicating successful password protection for the selected directory.
Step 5: Create authorized users
After saving protection settings, scroll to the ‘Create User’ section. Enter a username and password in the provided fields. Type the desired password twice in the spaces provided to confirm it. Tap ‘Save’ to add the user.
A confirmation message listing the new user under ‘Authorized Users’ will appear. You can repeat the process to add more users if necessary.
Step 6: Verify protection
Open a new window on your browser. Go to the protected page’s URL.
You should receive a prompt to enter the login credentials (username and password) of any account created under the ‘Authorized Users’ section. Entering the correct credentials will grant you access to the directory and its content.
Method 2: Password Protecting Single File Using .htaccess and .htpasswd
You can use the .htaccess and .htpasswd functions to protect just one file in a directory. The method provides greater control over specific files without restricting access to other files in the same directory.

Step 1: Log In to cPanel and access File Manager
Log in to cPanel and locate File Manager. Click on File Manager to access the interface that displays your site’s files and folders.
Step 2: Navigate to the file location
Browse to the folder where your file of interest is located. You can create a new folder to isolate this file if you desire targeted protection.
Step 3: Create or edit the .htaccess file
Next, check if an existing .htaccess file is in the directory.
- Right-click and select ‘Edit’ if it exists,
- Click ‘+File’ at the top of File Manager if the .htaccess file is not in the directory
Rename the file ‘.htaccess’ and click ‘Create New File’. Next, right-click the .htaccess file and tap ‘Edit’.
Step 4: Insert authentication directives into .htaccess
Paste this code into the .htaccess file and save your changes after minor edits (edit tips below):
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/username/.htpasswd
Require valid-user
(Replace /home/username/.htpasswd with the complete path where the .htpasswd file will reside. AuthName “Restricted Area” will define the text shown in the password prompt.)
Step 5: Create the .htpasswd File
Go to the directory where you plan to store the .htpasswd file. You can place it outside the ‘public_html’ directory for better security. Click ‘+File’ to create a new file and name the file ‘.htpasswd’ before tapping ‘Create New File’
Step 6: Generate an encrypted password
Next, use a trusted online .htpasswd generator by entering your login credentials. The generator will provide a long-form password. Copy this password and return it to File Manager. Next, right-click the .htpasswd file and tap ‘Edit’. Paste the generated code into the file and save changes before closing it.
Step 7: Test file protection
Open a new browser and enter the URL of the protected file. A prompt should appear requesting login credentials before granting you access. Enter the set credentials and ensure they match the .htpasswd entries. Keep the login credentials safe to avoid unauthorized access to your site content.
Tips for Added Page Security
Use strong passwords
Choose unique and strong passwords to protect files in your directory. Also, avoid easily guessed passwords when creating user accounts to access restricted pages or files.
Update credentials frequently
Perform ongoing security by updating passwords frequently while removing obsolete user accounts from Authorized Users on cPanel.
Monitor access logs
Monitoring your site’s access logs helps you detect unauthorized access attempts quickly and identify security issues before they become full data breaches.

Keep Sensitive Content Safe on Your Website
The guide provides two methods for password-protecting your site’s pages using cPanel. These steps can secure whole directories or individual files through the .htaccess and .htpasswd functions. Both methods provide reliable solutions for controlling access to your website’s content.
Remember to test access to these files after setting up password protection. Only those with the login credentials you set can access sensitive content on your site.
If you want an expert to help protect your site from unwanted visitors, you can contact us at anytime!
