Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Created December 7, 2017 19:32
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 davidbalbert/a250fc6e51fdd21897d9344ec15a8072 to your computer and use it in GitHub Desktop.
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.
#!/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