Generate strong passwords on Mac or Linux with APG

31 January 2008

APG (Automated Password Generator) is a command line app for generating passwords. I use it quite a bit on Linux and today I was poking around to see if I could use it on my Mac. It was easy to install with MacPorts. Assuming you have MacPorts installed, it’s just a matter of sudo port install apg. (To access a bunch of *nix apps, go ahead and install MacPorts: installing, using.)

APG gives you lots of options for generating passwords. Here’s what I like: apg -a 1 -n 1 -m 9 -M NCL -E 1iIloO0 , where

  • -a 1 = random (unpronouncable password)
  • -n 1 = number of passwords to generate
  • -m 9 = minimum length of passwords
  • -M NCL = must use number, capital letter, lowercase letter
  • -E 1iIloO0 = exclude 1iIloO0 (these are always tricky–it is a one or the letter l?)

For even more fun, let’s automate password generation in a little script.

#!/bin/bash
num=$1
if [ $num ] ; then
        echo $num | grep [^0-9] > /dev/null 2>&1
        if [ $?  -eq 0 ] ; then
                echo "only numbers please!"
                exit 1
        fi
else
        num=1
fi
apg -a 1 -n $num -m 9 -M NCL -E 1iIloO0

Just run the script with a number to generate that number of passwords, e.g. ./randompwd 5 would generate five passwords. If you run it without a number it just generates a single password.

Technorati Tags: , , ,

Leave a Reply