Skip to content

Instantly share code, notes, and snippets.

@jan-swiecki
Last active October 10, 2017 14:43
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 jan-swiecki/9974501047c79bad12a3c87cfe846cd6 to your computer and use it in GitHub Desktop.
Save jan-swiecki/9974501047c79bad12a3c87cfe846cd6 to your computer and use it in GitHub Desktop.
Passphrase generator for linux based on /dev/urandom and dict words available in linux
#!/bin/bash
# Usage: ./passphrase_gen.bash 4 > x && vim x
# We redirect to file and print via vim so no history is saved anywhere.
# Repeat after you get passphrase you like. Memorize it/write it down
# and remove x afterwards.
set -eo pipefail
words=/usr/share/dict/words
# https://serverfault.com/a/214620/216850
sudo rngd -r /dev/urandom
n=$1
# print $n randomly chosen words from $words file
for i in $(seq 1 $n); do
# https://unix.stackexchange.com/a/268960
random=$(od -vAn -N4 -tu4 < /dev/urandom)
lines=$(cat $words | wc -l)
line=$((random % lines))
awk "NR==$line" $words
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment