Skip to content

Instantly share code, notes, and snippets.

@cronfy
Last active April 11, 2020 21:55
Show Gist options
  • Save cronfy/6c01e7fe2c7b4fb913225fef375f3b28 to your computer and use it in GitHub Desktop.
Save cronfy/6c01e7fe2c7b4fb913225fef375f3b28 to your computer and use it in GitHub Desktop.
Make .htaccess and .htpasswd for dev
#!/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