Skip to content

Instantly share code, notes, and snippets.

@johanoloflindberg
Forked from jakebellacera/http-auth-basic.md
Last active August 29, 2015 14:15
Show Gist options
  • Save johanoloflindberg/60bade50f383a46ba281 to your computer and use it in GitHub Desktop.
Save johanoloflindberg/60bade50f383a46ba281 to your computer and use it in GitHub Desktop.

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