Skip to content

Instantly share code, notes, and snippets.

Last active August 21, 2023 12:33
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
how to generate password hash and salt for basic auth in solr

solr has a basic authentication module. the description of how to generate the necessary hash + salt string is very hazy. there is this:

project with java code extracted from the solr source .... and then there is this:

SALT=$(pwgen 48 -1)
echo "hash    : $(echo -n "$SALT$PW" | sha256sum -b | xxd -r -p | sha256sum -b | xxd -r -p | base64 -w 1024) $(echo -n "$SALT" | base64 -w1024)"

to run this, you need to have pwgen and vim-common installed, eg (fedora)

dnf install pwgen vim-common -y

pwgen can obviously be replaced by anything that produces random strings. vim-common contains the "xxd" binary to convert hexadecimal output of sha256sum to binary.

you can then call this script: "you_passw0rd"

and the out put goes in here:

"authentication": {
    "blockUnknown": true,
    "class": "solr.BasicAuthPlugin",
    "credentials": {
      "solr": "[***OUTPUT OF THE SCRIPT***]"

this script could be more elaborate - but i'd rather leave that as an execise to the reader :)

Copy link

RoSk0 commented Aug 18, 2021

xxd is a separate package on Ubuntu

Copy link

This is superb; thank you. Q: why is the sha256sum -b | xxd -r -p | sha256sum -b | xxd -r -p part duplicated? It's necessary, but I'm not following why that is.

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