six demon bag

Wind, fire, all that kind of thing!


Generate a Solr Password Hash With a Shell Script

In 2017 I published a small Java utility for generating Solr password hashes, because I didn't like launching Solr with well-known credentials. I would've preferred doing it with just a shell script, but found myself unable to replicate the hash creation process with sha256sum.

A couple days ago user rmalchow contacted me on Github with a solution for that, which I want to share here.

PW="${1:?Usage: $0 PASSWORD}"
SALT="$(pwgen 48 -1)"
echo "$(echo -n "${SALT}${PW}" | sha256sum -b | xxd -r -p | sha256sum -b | xxd -r -p | base64 -w 1024) $(echo -n "$SALT" | base64 -w 1024)"

If you don't want to install pwgen you can replace it with another password generator like apg:

apg -Mncl -a1 -n1 -m48 -x48

or by simply reading a number of bytes from /dev/urandom and base64-encoding them:

dd if=/dev/urandom bs=1 count=48 status=none | base64 | cut -c 1-48

Posted 15:28 [permalink]