Skip to content

Instantly share code, notes, and snippets.

@thsutton
Last active December 11, 2015 12:29
Show Gist options
  • Select an option

  • Save thsutton/4601205 to your computer and use it in GitHub Desktop.

Select an option

Save thsutton/4601205 to your computer and use it in GitHub Desktop.
Generate a random passphrase from the words in your system dictionary.
#!/bin/sh
#
# Generate an $N word passphrase from the words in $D.
#
N=6
D=/usr/share/dict/words
R=/dev/random
L=$(cat $D | wc -l)
od -An -tu4 -N $(expr $N \* 4) $R | \
xargs -n 1 -I @ sh -c "head -n \$(expr @ % $L) $D | tail -1" | \
tr "[:upper:]" "[:lower:]" | \
tr "\n" " "
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment