Created
December 7, 2017 19:32
-
-
Save davidbalbert/a250fc6e51fdd21897d9344ec15a8072 to your computer and use it in GitHub Desktop.
Generate a hashed password with random salt in the OpenLDAP SSHA format (seeded SHA-1). For use with FreeRADIUS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
if [ "$#" -lt 1 ]; then | |
echo "usage: $0 password" >&2 | |
exit | |
fi | |
SALT=$(head -c 18 /dev/urandom | base64 | tr -d '\n') | |
SSHA=$(echo -n "$1""$SALT" | openssl dgst -binary -sha1 | awk '{print $1}') | |
ENCODED=$(echo -n "$SSHA""$SALT" | base64 | tr -d '\n') | |
echo $ENCODED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment