iphu9a
Last Updated: February 25, 2016
·
553
· bt3gl
1396323302436

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
Say Thanks
Respond

2 Responses
Add your response

17461
0 5fq3tifqr0ecdb8vlwnttemqkrfrwl3vfshytedn7orinz9sddxdfhmzyv7xhnh9k290mf1zh3wt

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 ·
18063
Cfd59846a3f2c8a93a714a75e5eeff3f

debian & friends

apt-get install apg

suse & friends

yum install apg

osx

brew install apg

over 1 year ago ·
Filed Under