Skip to content

Instantly share code, notes, and snippets.

@izonder
Forked from surjikal/encrypt-pw-ssha.sh
Last active December 9, 2016 15:33
Show Gist options
  • Save izonder/04bbfd97c097782c25448ce811ca28ec to your computer and use it in GitHub Desktop.
Save izonder/04bbfd97c097782c25448ce811ca28ec to your computer and use it in GitHub Desktop.
Encrypt a password using SSHA. Use this for your `htpasswd` files.
#!/bin/sh
# http://wiki.nginx.org/Faq#How_do_I_generate_an_htpasswd_file_without_having_Apache_tools_installed.3F
#PASSWORD=$1;
read -p "enter password:" PASSWORD;
SALT="$(openssl rand -base64 3)"
SHA1=$(printf "$PASSWORD$SALT" | openssl dgst -binary -sha1 | sed 's#$#'"$SALT"'#' | base64);
printf "{SSHA}$SHA1\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment