SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

Protect a Directory with Apache, .htaccess and httpasswd

       

Apache comes with a command line utility called "htpasswd". This utility will generate a username and password that you can use to authenticate against using a .htaccess file. Just run the utility like so:


  htpasswd -c /path/to/your/password/directory/and-your-password-filename jane_doe_username
This will prompt you for a password/confirm password.

Keep in mind that this will not create a user on the system. It will just create a password and associate it with a string, that is the username you'll use to authenticate in your request.

Then you'll need to add a .htaccess file in the directory that you want to protect, and in that file place the following code.


AuthType Basic
AuthName "Restricted Directory"
AuthUserFile /path/to/your/password/directory/and-your-password-filename
Require user jane_doe_username

Remember that the /path/to/your/password/directory will need to be owned by Apache. on Ubuntu, it's by default the www-data user. Change ownership like so:


 chown -R www-data:www-data directory

Tagged w/ #.htacess #apache2 #httpasswdprogramming

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app