Skip to content

Instantly share code, notes, and snippets.

@stbuehler
Created July 1, 2020 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stbuehler/d2725d4e4291227b944d51d7dcd68a99 to your computer and use it in GitHub Desktop.
Save stbuehler/d2725d4e4291227b944d51d7dcd68a99 to your computer and use it in GitHub Desktop.
create ldap {SSHA} (salted sha1) password hashes
#!/bin/bash
tmpdir=$(mktemp --tmpdir -d create-ldap-ssha-XXXXXXX)
trap 'rm -rf "${tmpdir}"' EXIT
openssl rand -out "${tmpdir}/salt" 8
echo -n "Enter password: "
read -rs password
echo
echo -n "Confirm password: "
read -rs password2
echo
if [ "${password}" != "${password2}" ]; then
echo >&2 "Password mismatch"
exit 1
fi
hash=`(printf '%s' "${password}"; cat "${tmpdir}/salt") | (openssl sha1 -binary; cat "${tmpdir}/salt") | base64`
printf '{SSHA}%s\n' "${hash}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment