Script to generate passwords

When I need to generate temp passwords for users, I prefer simple alpha numeric passwords. If enough characters are used, they should be strong enough for most uses. Here's a little script I use to generate them:

1
2
3
4
5
#!/bin/bash
 
c="$1"
if [ -z "$1" ]; then c=20; fi
cat /dev/urandom | tr -cd [:alnum:] | head -c "$c" | xargs

Example output:

$ genpasswd 8
bc9qGozf

If length is unspecified, defaults to 20:

$ genpasswd
8bHFGgDao2KPYeS6STjE

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).