Generating a random password

A tool that I wrote last year to generate random passwords, and have since found unbelievably useful. Save it in a shell script and use at will. It takes one optional parameter, which is the password length (it defaults to 12 chars), and produces a typable password without problematic characters (such as quotes) that some badly-configured websites choke on.

if [[ -n $1 ]]; then 
< /dev/urandom tr -dc \
  _\!\@\#\$\%\^\&\*\(\)\<\>,.:\;+\-=\[\]\\/\?\|\~A-Za-z0-9 \
  | head -c$len 

6 thoughts on “Generating a random password

  1. That’s good for generating a random password but you still have the problem of remembering it. I think something that translates from a half-decent but memorable password to a better random one would be more useful. Obviously the translation must use a repeatable (pseudo-)random number generator(s). md5sum etc could be a useful starting point, e.g.

    echo “correcthorsebatterystaple” | md5sum

    OK, you’d probably want to translate that to randomly have some upper case letters and symbols as well, but you get the general idea. Everyone makes their own script. Beats the idiotic idea of using a commercial (esp. online) password manager.

    If the remote site makes you change your password frequently, just add a number to your memorable password, e.g.

    echo “correcthorsebatterystaple2” | md5sum

    echo “correcthorsebatterystaple3” | md5sum

    1. No, password managers are a great idea. Not online, but a local one with a good, hard but memorable master password. Everything else is randomised. Particularly if you’re doing it in a commercial environment where other people need to be able to recover your passwords.

      1. The problem with password managers is trust. How can you be sure that they are competent and are not a front for crooks looking to harvest all our passwords?

        “need to be able to recover your passwords.”

        Recover? Or reset?

      2. Yes, but the same criterion of trust applies to all the software on your computer, any of which could be a key logger in disguise. Password managers don’t increase that threat surface significantly. And yes, I mean recover. Ideally, all your passwords would be unique, user-based and memorable but that just doesn’t happen. Without universal deployment of federated ID services the management overhead would be enormous. And password recovery systems are generally dreadful – in many cases they’re orders of magnitude easier to break than passwords themselves (which we know are crap). Apple have been pretty bad at it, for example.

      3. Federated ID across multiple organisations or websites (e.g. “social login”) or federated ID across different websites within the same organisation? Former is far worse security wise than password managers, so OK, use managers, but at least insist that everyone uses a different one with a different master password for each site they log on to 🙂

        “And yes, I mean recover”

        Yes, password recovery systems (i.e. verfying that this is the correct person and we should help them get back into their account) are often vulnerable, but to clarify, do you mean that the sysadmins should be able to tell me what my old password was? I was just about to email a webstore to chide them for being able to do so for me.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s