Created
March 3, 2016 17:03
-
-
Save david-thorman/4fdf6beb4669d0c1ce5e to your computer and use it in GitHub Desktop.
Generate random passphrase on OSX with bash
This file contains hidden or 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 | |
# Only tested on OSX | |
DICT="/usr/share/dict/words" | |
CEIL=$(wc -l "$DICT" | tr -s '[:blank:]' ' ' | cut -d' ' -f2) | |
if [ "$#" -lt 1 ] ; then | |
LEN="5" | |
else | |
LEN="$1" | |
fi | |
i=0 | |
while [ "$i" -lt "$LEN" ] ; do | |
RN=$(dd if=/dev/urandom count=4 bs=1 2>/dev/null | od -t u | head -n1 | tr -s '[:blank:]' ' ' | cut -f 2 -d' ') | |
IDX=$(((RN % CEIL) + 1)) | |
sed "${IDX}q;d" "$DICT" | |
i=$((i+1)) | |
done | xargs echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment