Bash script to generate random passwords


Here I stumbled on an intro into Bash scripting for NetOps by John Kristoff " Introduction to Shell and Perl scripting for Network Operators" https://www.cymru.com/jtk/talks/nanog54-intro-scripting.pdf and could't help but do it my way. Here it is, bash script that generates random password of printable characters, up to 15 at least.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/bin/bash
# usage: randompass.sh [n] [count]  - n is number of characters in password
# to generate 9 by default, and count - number of passwords to generate, 1 by default
n=${1:-9}
counter=${2:-1}
for ii in `seq 1 $counter` ;do
dd count=1 bs=15  if=/dev/urandom 2>/dev/null |
   od -a   |
 sed '2d'  |
 sed 's/0000000 \(.*\)/\1/' |
 tr -d ' '  | cut -c 1-$n |
 sed 's/\([a-z]\)/\U&/3' |
 sed 's/\([A-Z]\)/\l&/4'
done

Download the script Example.

#randompass.sh 7 7

o&sOh;~K
deL(HMd
dc23DBg
HK?S@iE
_$SL*Ad
si|}Del
%I-ba<B

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.