Password generator for Linux - Bash Script
Posted 12-07-2011 at 12:05 PM by sudhagud
Getting on with system administration means to have a constant security aware work flow. I have written a simple script to generate a fairly complex password. By default it creates a 8 character length. If a length is given then it can be between 9-32. Anything above 32 is truncated to 32 characters and anything less than 9 is defaulted to 8.
Suggestions are welcome. The script itself.
Make things easy for yourself, use it and have fun.
- Bellamkonda Sudhakar
Suggestions are welcome. The script itself.
Code:
#!/bin/bash ################################################################## # # Script to generate a fairly complex password # ################################################################## # # Author: Bellamkonda Sudhakar # License: GNU GPL v3 ################################################################## VERSION=0.1 ################################################################## function uerror { printf "%s\n" "Not root" } function numerr { printf "%s\n" "Numbers only" } ################################################################## function usage { printf "\n%s\n" "Password Generator V0.1" printf "\n%s" "pwgen <Option>" printf "\n%5s%s" " " "-n where n can be a numeric between 9-32, when not given default is 8" printf "\n%5s%s\n" " " "-h displays this usage page" } ################################################################# function pgen { PASSWORD=`tr -dc A-Za-z0-9_ < /dev/urandom | head -c $L` printf "%s\n" "$PASSWORD" } ################################################################## #Main Program L=8 # if [ $UID -ne 0 ] ; then uerror; exit 0; fi # if [ "$1" == "-h" ] ; then usage; exit 0; fi # if [ $# -eq 0 ] ; then pgen; exit 0; fi # if [ $1 -eq $1 2>/dev/null ] then if [ $1 -gt 32 ] ; then L=32; fi if [ $1 -lt 32 -a $1 -gt 8 ] ; then L=$1; fi pgen else numerr usage exit 0 fi
- Bellamkonda Sudhakar
Total Comments 1
Comments
-
There are some other easier ways to generate a password in bash.
As an example,
date +%s | base64 | sha256sum | head -c 16 ; echo
Some other ways are listed at this page.Posted 11-07-2014 at 10:30 AM by illiak