1. Log in to your cPanel account
2. Go to Files > File manager
3. In the home directory, create a new file and name it .htpasswd (this file will not be visible to visitors)
4. Create an encrypted password using an htpasswd generator
Note: All protected files will use the same .htpasswd file.
5. In the htpasswd generator, enter a username and a password of your choice and generate an encrypted password
6. Copy the encrypted password, paste it in the .htpasswd file and click Save Changes
Now you need to add the code below in .htaccess file replacing ProtectFileName.extension with the name of the file you wish to protect and Usename with the username of your choice and click Save Changes
<FilesMatch "ProtectedFileName.extension" >
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/Username/.htpasswd
require valid-user
</FilesMatch>
Note: If you cannot find an .htaccess file on your account, you can create one by clicking on +File
This will allow you to protect the file, while keeping all other files on the same folder unprotected .