How to generate a random password using the command line.

The shuf command for Linux allows a command-line user to select a given number of random words from a wordlist.

[jason@localhost ~]$ shuf -n 8 /usr/share/dict/words
amphivasal
thoracically
U.
bluet
Dabih
thioamid
taxiing
convictism

This can be used to generate a word based password using piping. The example below shows how to generate a random password using the command line.

[jason@localhost ~]$ shuf -n 4 /usr/share/dict/words | paste -s -d ''
denaturizingdevastercomediettasSyryenian

This is another example, this generates a random password string that may be used for any login.

[jason@localhost ~]$ shuf -n 4 /usr/share/dict/words | awk '{print toupper(substr($0,1,1)) substr($0,2)}' | cut -d\' -f1 | tr -d '\n' ; echo
MoulviRagshagMacroglobulinemicColor-fading

Yet another example, generate an unbreakable password.

[jason@localhost ~]$ tr -dc "[:print:]" < /dev/urandom | head -c 128 ; echo
C+4r^ai05+^Z]ZtdC3&E~d&15BesG.}{EVI[+Oqb0e,kA8:RB!\7`h]rn=$Mz|:A7/ODh1^YOL3NE|KLWD/*oTJ}!&q2b?SB^?<B}}u5{r1.NmK~KL&hpU';mwr6D6lH

No comments have been made. Use this form to start the conversation :)

Leave a Reply