Last active
April 11, 2020 21:55
-
-
Save cronfy/6c01e7fe2c7b4fb913225fef375f3b28 to your computer and use it in GitHub Desktop.
Make .htaccess and .htpasswd for dev
This file contains 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
#!/usr/bin/env bash | |
# Creates .htaccess and .htpasswd in current directory to protect site with password | |
# Default login/password are dev/dev | |
[ -e .htaccess ] && { | |
echo " !! .htaccess already exists! Exiting." >&2 | |
exit 1 | |
} | |
[ -e .htpasswd ] && { | |
echo " !! .htpasswd already exists! Exiting." >&2 | |
exit 1 | |
} | |
# for ifconfig | |
export PATH=/sbin:$PATH | |
{ | |
echo -e " | |
# https://stackoverflow.com/a/8855016/1775065 | |
Satisfy any | |
AuthType Basic | |
AuthName \"Password Protected Area\" | |
AuthUserFile `realpath .`/.htpasswd | |
Require valid-user | |
Order deny,allow | |
Deny from all" | |
# allow from all localhost ips | |
ifconfig | grep 'inet ' | awk '{print "Allow from " $2}' | |
} > .htaccess | |
# login dev, password dev | |
echo -e 'dev:$apr1$5IGvr56c$FLQInei/j4rNTYmCOAdjJ/ | |
' > .htpasswd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment