genpasswd

#!/bin/sh
# genpasswd.sh
#   Generate a random password with almost
#   144 bits of randomness, making use of
#   /dev/random.
# Note:
#   Most online services have somewhat
#   arbitrary rules about what characters
#   can be included in a password. So we
#   limit ourselves to A-Za-z0-9.
# Copyright 2007 Hal Canary
# Dedicated to the Public Domain.
echo "Grabbing bits from /dev/random..." 1>&2
head -c 18 /dev/random | base64 | \
        sed 's/\//Z/g;s/+/z/g;'
# If you lack base64 on your system, try:
# head -c 18 /dev/random  | uuenview -b '' | \
#       sed 's/\//Z/g;s/+/z/g;'

Exactly how much entropy do we get?

Each character can be a z or a Z with a probability of 2/64 for each. The other 60 characters have a probability of 1/64 each. Apply the formula:

information entropy
    = ∑(i=1, n, p(x[i]) log2(1 / p(x[i])))
    = ∑(i=1, 2, 2/64 *  log2(64/2)) + ∑(i=1, 60, 1/64 * log2(64/1))
    = 2 * (2/64) * log2(64/2) + 60 * (1/64) * log2(64/1)
    = 2 * (2/64) * 5 + 60 * 1/64 * 6
    = 20/64 + 360/64
    = 380/64
    = 5.9375

Mulitply by 24 for 24 characters, and get 142.5 bits of entropy.