Skip to content

Instantly share code, notes, and snippets.

@phrawzty
Created January 24, 2012 15:35
Show Gist options
  • Save phrawzty/1670720 to your computer and use it in GitHub Desktop.
Save phrawzty/1670720 to your computer and use it in GitHub Desktop.
Scipt to generate SHA-512 password fields suitable for /etc/shadow. Requires a relatively recent version of mkpasswd.
#!/bin/bash
if [ "x$1" == 'x' ]; then
echo "USAGE: $0 '<password>'"
exit 1
fi
# Get an md5sum of the string for eventual extraction.
md5=$( echo $1 | md5sum )
extract="${md5:2:8}"
mkpasswd -m SHA-512 "$1" "$extract"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment