HTAccess + HTPasswd

From SysadminPunk Wiki!

Jump to: navigation, search

Contents

Create .htaccess File

vi /var/www/sitename/.htaccess

.htaccess file contents

order deny,allow
deny from all
allow from 10.0.1
allow from 10.0.10
allow from 10.1.0
allow from 172.16.0
allow from 228.28.28
allow from 35.135.35
AuthType Basic
AuthName "Auctiva Protected Area"
AuthUserFile /var/www/Directory/.htpasswd
Require valid-user
  • Obviously you would fix the path here before saving

Edit Permissions for .htaccess

chmod 644 .htaccess

Create .htpasswd File

htpasswd -bc /path/to/.htpasswd admin admin_password
htpasswd -b /path/to/.htpasswd username password
  • For the First user you add the user and password with -bc for subsequent users just use -b
 Usage:
	htpasswd [-cmdpsD] passwordfile username
	htpasswd -b[cmdpsD] passwordfile username password
 	htpasswd -n[mdps] username
	htpasswd -nb[mdps] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -m  Force MD5 encryption of the password.
 -d  Force CRYPT encryption of the password (default).
 -p  Do not encrypt the password (plaintext).
 -s  Force SHA encryption of the password.
 -b  Use the password from the command line rather than prompting for it.
 -D  Delete the specified user.

Edit Permissions for .htpasswd

chmod 644 /path/to/.htpasswd
  • This would have to match your .htaccess file.
Personal tools