From 55731ee0a77d3798d2ce10ed72b9c59ef342e09d Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 9 Sep 2017 13:33:02 +0800 Subject: Add htpasswd.sh script --- cli/htpasswd.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 cli/htpasswd.sh diff --git a/cli/htpasswd.sh b/cli/htpasswd.sh new file mode 100755 index 0000000..df5c297 --- /dev/null +++ b/cli/htpasswd.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# +# Generate htpasswd (Apache password file) without installing Apache tools. +# +# Credit: +# * NGINX: FAQ +# https://www.nginx.com/resources/wiki/community/faq/ +# * How to get a password from a shell script without echoing +# https://stackoverflow.com/a/3980713/4856091 +# +# +# Aaron LI +# 2017-09-09 +# + +if [ $# -ne 1 ]; then + echo "usage: ${0##*/} " + exit 1 +fi + +USER="$1" + +# Disable echo ... +stty -echo +printf "Password: " +read PASS1 +printf "\n" +printf "Password (again): " +read PASS2 +printf "\n" +# Enable echo +stty echo + +if [ "${PASS1}" != "${PASS2}" ]; then + echo "ERROR: passwords do not match!" + exit 2 +fi + +# Use the UNIX "crypt" encryption +printf "${USER}:$(openssl passwd -crypt ${PASS1})\n" -- cgit v1.2.2