Skip to content

Instantly share code, notes, and snippets.

@jazlopez
Forked from samba/htpasswd-ssl.sh
Created December 31, 2022 19:42
Show Gist options
  • Save jazlopez/d8aaa5f2ef63973820ab7ecb3f9f76f7 to your computer and use it in GitHub Desktop.
Save jazlopez/d8aaa5f2ef63973820ab7ecb3f9f76f7 to your computer and use it in GitHub Desktop.
htpasswd replacement with openssl
#!/bin/sh
# Writes an APR1-format password hash to the provided <htpasswd-file> for a provided <username>
# This is useful where an alternative web server (e.g. nginx) supports APR1 but no `htpasswd` is installed.
# The APR1 format provides signifcantly stronger password validation, and is described here:
# http://httpd.apache.org/docs/current/misc/password_encryptions.html
help (){
cat <<EOF
Usage: $0 <htpasswd-file> <username>
Prompts for password (twice) via openssl.
EOF
}
[ $# -lt 2 ] && help;
[ $# -eq 2 ] && printf "${2}:`openssl passwd -apr1`\n" >> ${1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment