Skip to content

Instantly share code, notes, and snippets.

@ocean90
Created May 30, 2013 20:42
Show Gist options
  • Save ocean90/5681040 to your computer and use it in GitHub Desktop.
Save ocean90/5681040 to your computer and use it in GitHub Desktop.
Password Generator for the console
################
# Password Gen #
################
# Source: http://blog.colovirt.com/2009/01/07/linux-generating-strong-passwords-using-randomurandom/
# Use: `pwgen` or pwgen 20 oder pwgen 20 10
pwgen() {
# Length of password
if [ -z "$1" ]
then
length=10
else
length=$1
fi
# Number of passwords
if [ -z "$2" ]
then
limit=4
else
limit=$2
fi
# fix "tr: Illegal byte sequence" error
export LC_ALL=C
# Generate the password, check also that an additional character exists
cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w $length | head -n $limit | grep -i '[!@#$%^&*()_+{}|:<>?=]'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment