Sometimes we need an easy way to password protect files and folders in *nix based systems that use Apache as a webserver. We would simply need to create 2 files 2 accomplish this. An .htaccess file and a .htpasswd file. While the name of the .htpasswd file could be anything it is important to make sure our .htaccess file refers to this specific file. Please see the examples below.
Example: creation of .htpasswd file for a user name “admin” and the file name “.htpasswd” . You can change the file name “.htpasswd” and user name “admin” to other values that you like. As soon as the type the command below the *nix based system will ask you to enter a value for the password 2 times for verification purposes.
htpasswd -c .htpasswd admin
Example .htaccess file for a “.htpasswd file” located in “/var/www/sites/itmontreal.ca/htdocs/.htpasswd” the popup that will ask for the user name / password combination will say “Administration Area” you can change this to say something else if you prefer.
AuthUserFile /var/www/sites/itmontreal.ca/htdocs/.htpasswd
AuthType basic
AuthName “Administration Area”
require valid-user
Administration of *nix based systems is not an easy task it requires one to spend significant amount of time and knowledge.We can help! Please visit http://www.itmontreal.ca/contactus.php and fill out the “contact us” form to benefit from our professional, paid services.