Elegant bash one liner to generate passphrase

Published by Arun Isaac on

In other languages: தமிழ்

Tags: software, bash

An elegant bash one liner to generate a passphrase – shuf from coreutils is the secret ingredient.

Just last week, I wrote a full-fledged bash script to generate a passphrase. Klaus Jönsson Zimmermann on GNU Social showed me a much more elegant one liner. Here it is, adapted to work on diceware type lists and to use /dev/random as the random source.

shuf --random-source /dev/random diceware.wordlist.asc | head -n 6 | cut -f 2 | tr '\n' ' '

And, if you prefer it with yucky unreadable but short awk,

shuf --random-source /dev/random diceware.wordlist.asc | awk 'NR <= 6 {printf "%s ", $2}'