Skip to content

Instantly share code, notes, and snippets.

@deepfriedmind
Created August 29, 2014 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepfriedmind/b8df8dc5517b0afc2728 to your computer and use it in GitHub Desktop.
Save deepfriedmind/b8df8dc5517b0afc2728 to your computer and use it in GitHub Desktop.
HTPGen – Quickly generate .htpasswd / .htaccess files for basic Apache authentication. To be able to run `htpgen.sh` from anywhere, place the file somewhere that's included in your `PATH`, e.g. `/usr/local/bin` or `/usr/bin`.
#!/bin/bash
read -p "Enter username: " -r ht_username
read -p "Enter password: " -sr ht_password
echo -en "\n"
read -p "Enter full path to where .htpasswd will be placed on the web server: " -r ht_path
htpasswd -nb $ht_username $ht_password > .htpasswd
echo "AuthType Basic
AuthName \"Log in\"
AuthUserFile $ht_path
Require valid-user" > .htaccess
echo "
.htaccess / .htpasswd files created in $PWD
Username: $ht_username
Path: $ht_path
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment