Skip to content

Instantly share code, notes, and snippets.

@jakebellacera
Created January 9, 2012 21:18
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jakebellacera/1584987 to your computer and use it in GitHub Desktop.
Save jakebellacera/1584987 to your computer and use it in GitHub Desktop.
How to secure a folder with Basic HTTP Authentication

Basic HTTP Authentication is when a user is required to log in to access a directory. This isn't meant to be secure by any means, but it's useful for locking out a majority of users from accessing a folder (e.g. staging a website).

To start, you must add this into your .htaccess:

AuthUserFile "/var/www/full/path/to/your/folder/.htpasswd"
AuthName "Message to go on user's login screen"
AuthType Basic
Allow from all
Require valid-user
Options +Indexes

It's recommended to have the .htpasswd outside of your public directory (if possible).

Next, generate an .htpasswd. Run this command on your server's console:

htpasswd -bc /var/www/full/path/to/your/folder/.htpasswd username password

You can specify what username/password combination you'd like.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment