Last Updated: February 25, 2016
·
1.314K
· bt3gl

Creating Pseudo-Random Passwords in Linux

Add this to your ~/.bashrc:

genpass() {
    local p=$1
        [ "$p" == "" ] && p=16
        tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${p} | xargs
}

To generate the passwords, just type:

$ genpass

Examples:

$ genpass
dIBObynGX9epYogz
$ genpass 8
c_yhmaXt
$ genpass 12
FZI2wz2LzyVQ
$ genpass 14
ZEfgQvpY4ixePt

2 Responses
Add your response

For Mac OSX (at least Yosemite), I had to do the following to make it work (and expand what it could do):

genpass() {
local p=$1
[ "$p" == "" ] && p=16
LCCTYPE=C tr -dc A-Za-z0-9!\@#\$\%^&*()-+= < /dev/urandom | head -c ${p} | xargs
}

over 1 year ago ·

debian & friends

apt-get install apg

suse & friends

yum install apg

osx

brew install apg

over 1 year ago ·