Get the highlights in your inbox every week.
Generate random passwords with this Bash script | Opensource.com
Generate random passwords with this Bash script
Take the hassle out of picking passwords with this simple Bash script.
Periodically, I need to come up with new passwords, some of which need to be more secure than others. My mind often seems to draw a blank when I have to create a new login, and this short Bash script fills that void. Full disclosure: I found most of this script posted somewhere and made a minor modification to it.
echo 'Generating 12-character passwords'
do dd if=/dev/urandom count=1 2> /dev/null | uuencode -m - | sed -ne 2p | cut -c-12
I don't know all the details of how this works, but I have done a bit of research and experimentation. The "meat" of the script is in the line beginning with do dd. You may have seen dd used to copy one disk to another, but in this case, it is used to generate one block of random characters with dev/urandom. The feedback messages from dd are stripped out, and then the characters are passed on to uuencode, whose job it is to transform the characters so that all are printable (i.e., no control characters).
The uuencode command can be obtained by installing the sharutils package.
The job of sed seems to be some further transformation so that the letters are mixed upper and lower case. Finally, cut slices off 12 characters to end with a 12-character password. The for loop runs 12 times, so you get 12 passwords.
Generating 12-character passwords
This example output shows a pretty good jumble of characters. One thing to notice is that the only non-alphanumeric characters are / and +.When I need a new password, I look through this output for one that "appeals" to me. If it's a password I will use frequently, I'd rather it be something I think I can eventually remember.
There is no reason to use these literally as they are; you can add or modify characters as you want. I mostly use eight-character passwords. Some places require a password to have specific elements, such as at least one lower-case letter, one upper-case letter, one number, and one symbol.
If I don't like any of the passwords, I run the script again to generate another 12. Someone might comment that dev/urandom only generates pseudo-random numbers, but this script certainly does a much better job than I could do on my own.