Edit /etc/apache2/sites-available/default
Find the directory you want to protect (in my case: /usr/lib/cgi-bin) and change the "AllowOverride" line from "none" to "AuthConfig". Here's how the cgi-bin section of my file is after changing:
Now I create an user (gfcaetano) and a password, storing them into the file "/etc/apache2/.htpasswd" with htpasswd command:
htpasswd -c /etc/apache2/.htpasswd gfcaetanoIt will ask you for the password (twice).
The next step is to create the ".htaccess" file into cgi-bin directory so it will ask for the password when entering at cgi-bin folder of this Apache2 server.
Edit or create /usr/lib/cgi-bin/.htaccess and put the following lines into it:
Now Apache2 must me reloaded, run "/etc/init.d/apache2 reload".
That's it. Your Apache's cgi-bin directory is protected.
If you've noticed any errors at this post or if you have any suggestions, please notify me so I'll correct them.
Thanks for reading!