On Tue, Aug 22, 2017 at 10:04:59AM -0500, Mario Castelán Castro wrote: > I have the following line in my Bash init file: > > “alias gen-password="head -c 16 /dev/urandom | base64 | head -c 22 && echo"” > > This generates a password with just above 128 bits of entropy. You may > find it useful.
Three POSIX-compliant shell functions that rely on no extra utilities outside of standard base installs. shuff() is needed for some BSD systems where shuffle(1) is used in place of shuf(1): shuff () { if [ $(command -v shuf) ] then shuf -n "$1" elif [ $(command -v shuffle) ] then shuffle -f /dev/stdin -p "$1" else awk 'BEGIN{ "od -tu4 -N4 -A n /dev/urandom" | getline srand(0+$0) } {print rand()"\t"$0}' | sort -n | cut -f 2 | head -n "$1" fi } gen_monkey_pass () { I=0 [ $(printf "$1" | grep -E '[0-9]+') ] && NUM="$1" || NUM="1" until [ "$I" -eq "$NUM" ] do I=$((I+1)) LC_CTYPE=C strings /dev/urandom | grep -o '[a-hjkmnp-z2-9-]' | head -n 24 | paste -s -d \\0 /dev/stdin done | column } gen_xkcd_pass () { I=0 [ $(printf "$1" | grep -E '[0-9]+') ] && NUM="$1" || NUM="1" [ $(uname) = "SunOS" ] && FILE="/usr/dict/words" || FILE="/usr/share/dict/words" DICT=$(LC_CTYPE=C grep -E '^[a-zA-Z]{3,6}$' "$FILE") until [ "$I" -eq "$NUM" ] do I=$((I+1)) printf "$DICT" | shuff 6 | paste -s -d '.' /dev/stdin done | column } They can optionally take an argument on how many passwords to generate: $ gen_monkey_pass 10 rq5xm9b7-jn2-s76-v7rymj2 pe9txqkuprr3nn9yczsp23rb uxsx4-673xcv7wkeu7c8g66k 88qd-y549n5pg3g87v33yetw tbf6nrnbub8q39wqt943cjas ts64jgxjw7ut84--2cw6uzxj vk4am2pr8nbuvr3e4gk7tsnm uhdsby7838gkgpnqjzvy73jm 2ckgppd7c2uasbd598-44z6z se8-74smtafh4h9dmeyschkc $ gen_xkcd_pass 10 irking.bidets.listen.Soyuz.dahlia.supped boob.lacing.peyote.glob.lack.trifle shirt.gushed.Aron.notch.agates.Fergus hewed.burlap.wales.beck.prisms.rangy route.retook.gills.cilium.wadis.gem stools.scurf.lugged.mooch.skater.throng heist.bye.Google.shyly.Tutsi.rip taboo.queues.totes.moors.Suzhou.newest sawyer.gill.clutch.opts.zits.larch Eisner.sulks.Bradly.Schulz.Adler.puking -- . o . o . o . . o o . . . o . . . o . o o o . o . o o . . o o o o . o . . o o o o . o o o
signature.asc
Description: PGP signature