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,633
Replies
13
Views
4,680
fwh
Replies
6
Views
4,518
Replies
6
Views
4,545
Recommended Threads
Replies
2
Views
2,809
Replies
2
Views
1,432
Replies
1
Views
3,325

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