Skip to content

Instantly share code, notes, and snippets.

@myano
Last active December 14, 2015 02:49
Show Gist options
  • Save myano/5016700 to your computer and use it in GitHub Desktop.
Save myano/5016700 to your computer and use it in GitHub Desktop.
This will convert a given password "foobar" into the SHA output that Apache uses for it's .htpasswd files. You can take the output of this command and simply append it with a "username_here:{SHA}" and then place it into a .htpasswd is pointing at. This is useful if you want someone to generate a password for you but they don't have Apache instal…

Without salt:

$ echo -n "foobar" | sha1sum | cut -d' ' -f1 | xxd -r -p | base64

With salt:

$ USR="yourname";PWD="foobar";SALT="$(openssl rand -base64 3)";SHA1=$(printf "$PWD$SALT" | openssl dgst -binary -sha1 | sed 's#$#'"$SALT"'#' | base64); echo "$USR:{SSHA}$SHA1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment