How do you password protect a file on my hosting

Gmeister4

Well-known member
Registered
Joined
Apr 19, 2016
Messages
178
Points
18
I could use the function in my web hosting panel to protect a folder with my password but I could not find a same function for protecting a file. Do you guys know?
 

LJSHost

Well-known member
Hosting Provider
Registered
Joined
Jul 5, 2016
Messages
1,031
Points
63
Hi Gmeister4,

To password protect an individual file:


1. Create a file named .htpasswd and place it above your root directory, so visitors can't access it. For example /home/accountname/.htpasswd
2. Create an encrypted password using htpasswd (if you have command linux access) or use a tool such as http://www.htaccesstools.com/htpasswd-generator/
3. add the generated username and password to the .htpasswd file, should look something like: privateuser:$apr1$G6l1bvsQ$Bop16v4jbGOlDd/3.YdFl0
4. Navigate to the directory where the file that you would like to password protect is located.
5. create a .htaccess file in this directory and add the following to the file.

<FilesMatch "examplefile.extension">
AuthName "Private"
AuthType Basic
AuthUserFile /home/username/.htpasswd
require valid-user
</FilesMatch>
replace examplefile.extension with your file's actual name.
This will protect only the specified file.
 

LJSHost

Well-known member
Hosting Provider
Registered
Joined
Jul 5, 2016
Messages
1,031
Points
63
If you are using cPanel it is as easy as clicking on "Password Protect Directories"
This is not what the OP asked, restricting access per file is not functionality that cPanel provides
 
Newer Threads
Replies
2
Views
2,399
Replies
13
Views
4,276
fwh
Replies
6
Views
3,987
Replies
6
Views
4,131
Recommended Threads
Replies
7
Views
4,301
Replies
10
Views
4,523
fwh
Replies
4
Views
2,440

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top