..


Sponsored Links

Restrict access to a folder with authentication

Article written by Max Bossi

In this short article we will see how to use Apache to restrict access to a folder to only users with a username and password.

To achieve our purpose we can simply resort to the usual. Htaccess file in combination with. Htpasswd.

First we set the contents of the file. Htaccess as follows:






 AuthUserFile / home / sites / www.sito.com / private / .htpasswd







 AuthName "Protected Area"







 AuthType Basic







 Require valid-user



It 'very important to correctly specify the path to the AuthUserFile. Htpasswd file.

Now we see how to create the file. Htpasswd whose content should have the following syntax:






 user1: password1_criptata







 user2: password2_criptata







 user3: password3_criptata



To create the file. Htpasswd can follow two paths:

1) if we have access to the shell of we make our server log on the machine and go to the folder where we create the file in question:

 



 cd / home / sites / www.sito.com / private /

 
and type:
 



 htpasswd-c. htpasswd username

 
now the system will ask password to associate with this user, password, which will then need to confirm.
And that's it: our system has generated for us. Htpasswd file!

2) If you do not have access to the shell of the server you will need to use a little trick.
Basically we can create "by hand" our. Htpasswd file used by one of the many scripts and tools available on the Web Here are some links:

Once generated the file will only have to save it and upload it to our web folder using a standard FTP client.

Because everything is working properly, of course, you must have. Htaccess file is in the same folder that you want to protect, but it is not necessary that you are in the same folder. Htpasswd (the important thing is that it is correctly indicated the path to get there) .

Now try to access the protected folder via http, if it works the web-server should return a logon prompt to insert the username and password.

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links