Created
February 2, 2014 22:03
-
-
Save alternatex/8775594 to your computer and use it in GitHub Desktop.
Basic Auth // Apache // Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Apache2 Basic Auth Directory Protection Helper | |
# === | |
# Note: `AllowOverride All` must be enabled for the given directory | |
# gather current directory | |
cwd=${PWD##*/} | |
# create directory to store password file | |
pwdirectory=/var/tmp/insecure/"$cwd"-pw | |
mkdir -p "$pwdirectory" | |
# create password file | |
htpasswd -c "$pwdirectory/.htpasswd" $cwd | |
# password file mustn't be placed into a directory accessible by public | |
echo "deny from all" > "$pwdirectory/.htaccess" | |
# basic auth | |
echo "AuthType Basic" > .htaccess | |
echo "AuthName \"Restricted Access\"" >> .htaccess | |
echo "AuthUserFile $pwdirectory/.htpasswd" >> .htaccess | |
echo "Require user $cwd" >> .htaccess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment