FOSS Unleashed

Password Generation with `dd`

Here’s a short one-liner to generate a 76 character password in bourne shells (IE: bash, zsh):

dd if=/dev/urandom count=1 bs=57 2>/dev/null | base64

In rc-based shells the same:

dd if=/dev/urandom count=1 bs=57 >[2]/dev/null | base64

On certain systems you might need to use /dev/random instead.

One thing to note that the block size of “57” seems a little paticular. Any larger and the output would spill over into another line as the base64 program will line-wrap its output. Additionally, if you wanted multiple passwords, you could provide a different value to count=. Or make a function:

# bourne shells
function randpw() {
    count="${1:-1}"
    dd if=/dev/urandom count=$count bs=57 2>/dev/null | base64
}

# xs
fn randpw {|count|
    if {~ $count ()} {
        count = 1
    }

    dd if=/dev/urandom count=^$count bs=57 >[2]/dev/null | base64
}

TODO: find out if plan9 actually has /dev/random.