0

I have installed apache2 in my server(subDomain.myserver.com) and i placed more folders in /var/www path. I want to do that when the user access subDomain.myserver.com/privateFolder then it should ask password prompt, if the password is valid then show the contents inside the private folder.

Note : I am using linux ubuntu for my server.

How to achieve this?

I tried based on answer :

sudo htpasswd -c /home/user/.htpasswd somename

and then vi .htaccess and added lines like below,

AuthName "Secure folder"
AuthType Basic
AuthUserFile /home/user/.htpasswd
require valid-user

and then i moved that .htaccess file into /var/www/protectedContentsHere/.htaccess

But still i can access that all folders inside /protectedContentsHere without prompt box.

where am i doing wrong?

MMMMS
  • 2,179
  • 9
  • 43
  • 83

1 Answers1

0

Generate a .htpasswd file by logging into your webserver using SSH

htpasswd -c /somefolderthatisntinapublicwebdirectory/.htpasswd a-user-name

Or generate a file online here htpasswd generator and upload it through ftp.

Do not put it in a directory (like /var/www), there might be a risk that a user can download the file if you do this.

Create a new file called ".htaccess" and add/upload it to /var/www/privateFolder:

AuthName "Secure folder"
AuthType Basic
AuthUserFile /somefolderthatisntinapublicwebdirectory/.htpasswd
require valid-user
Viktor Sarström
  • 510
  • 4
  • 16