Once in a while, someone would re-invent the wheel of random password generator, which must have been done enormous times, but people still think that ‘I can do better, I can make a better generator.’ Whether one can do better than thousands of forerunners or not, it’s not the point of this post, the fact is: you don’t need one if you really want to generate a password.

Here is the proof:

$ </dev/urandom tr -dc '[[:print:]]' | fold -w 8 | head -1
5*l?;*8<

The usage of tr and fold for password generation has already been seen in many forum and blog posts. I am not the first one to think of such usage. Here are a few notes about the command:

  • The source is /dev/urandom and there is also a /dev/random, which you might want to use like the following command, instead:

    $ head -c 100 /dev/random | tr -dc '[[:print:]]' |
      fold -w 8 | head -1
    ]9EOH48!
    
  • tr -dc means deleting those characters ain’t in [:print:] character class, for other and detail included character, you can check out Character classes or info 'tr' 'Character sets'.

  • fold makes sure you have 8-character in length password.

  • head limits to only generate one set of password.

If you want an alphanumeric one:

$ </dev/urandom tr -dc '[[:alnum:]]' | fold -w 8 | head -1

[:alnum:] is equivalent to [:alpha:][:digit:] and if you only need lower case, that would be [:lower:][:digit:].

So, you see, you don’t need a generator, just a few dozens of characters can get you your own customized password generator.


By the way, the one I just saw is a Python package and not a good one, judging by the package owner also added foo.egg-info, dist, bar.swp, __pycache__, and a few others into the repository, those can clearly tell me how new this guy is to version control system. It always looks strange to me why so many people are very new to something and haven’t got a clue of how to use tools, and they are even creating packages for the stuff they made.