On Mon, 19 Jun 2017 07:37:35 +0200
Heinz Diehl <htd+ml(a)fritha.org> wrote:
Pwgen uses /dev/urandom, so the statement that those passwords are
less secure than "fully" random passwords (define "fully random"..)
is
merely of academical nature.
In case of any doubt, you can always do something like
head /dev/random | tr -dc A-Za-z0-9 | head -c X
where X is your password length. Tr also lets you tailor the
characterset used.
Here's my shell hack to generate passwords using the above. It saves
the passwords in the file devurandom_password.txt in the home directory.
#! /bin/bash
# generate a password using a character set, /dev/urandom,
# and tr to select the characters included.
# The three arguments are
# the character class to use to generate the password (default alnum)
# and
# the length of the password (default 20)
# and
# the number of passwords to generate (default 10)
DPW=/home/$USER/devurandom_password.txt
if [ "$#" = 0 ]; then
set an 20 10
elif [ "$#" = 1 ]; then
set $1 20 10
elif [ "$#" = 2 ]; then
set $1 $2 10
fi
echo "Passwords from /dev/urandom with $1" > $DPW
echo '' >> $DPW
for ((x = 0 ; x < $3 ; x = x + 1)) ; do
if [ "$1" = an ]; then
echo $(head /dev/random | tr -dc [:alnum:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = al ]; then
echo $(head /dev/random | tr -dc [:alpha:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = cn ]; then
echo $(head /dev/random | tr -dc [:cntrl:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = di ]; then
echo $(head /dev/random | tr -dc [:digit:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = gr ]; then
echo $(head /dev/random | tr -dc [:graph:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = lo ]; then
echo $(head /dev/random | tr -dc [:lower:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = pr ]; then
echo $(head /dev/random | tr -dc [:print:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = pu ]; then
echo $(head /dev/random | tr -dc [:punct:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = sp ]; then
echo $(head /dev/random | tr -dc [:space:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = up ]; then
echo $(head /dev/random | tr -dc [:upper:] | head -c $2) >> $DPW
echo '' >> $DPW
elif [ "$1" = xd ]; then
echo $(head /dev/random | tr -dc [:xdigit:] | head -c $2) >> $DPW
echo '' >> $DPW
else
echo $(head /dev/random | tr -dc [:alnum:] | head -c $2) >> $DPW
echo '' >> $DPW
fi ;
done
exit 0 ;