Elegant bash one liner to generate passphrase

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 --head-count 6 --repeat --random-source /dev/random diceware.wordlist.asc | cut -f 2 | tr '\n' ' '

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

shuf --head-count 6 --repeat --random-source /dev/random diceware.wordlist.asc | awk '{printf "%s ", $2}'
UPDATE (March 13, 2023)
Strengthen security by sampling with replacement.