$ openssl rand -base64 12However, I needed the password simple enough to give to users which meant I needed to remove the special characters. I know, removing special characters decreases security and increases the attack vector. However, these are SFTP accounts that are chrooted with no shell ... so I'm not too concerned. Moving forward, I decided to use sed to remove the characters:
Elg6gD/+jGAl88/S
$ echo "Elg6gD/+jGAl88/S" | sed 's/\///g' | sed 's/\+//g' | sed 's/\=//g'Goodie. Now, I need to keep it out of memory and store it in a randomly named temporary text file; mktemp to the rescue! With that in mind, I now had everything I needed to build a function:
Elg6gDjGAl88S
makepass (){Now, implementing it was easy as one, two, three:
local TMPFILE=$(eval mktemp)
openssl rand -base64 12 > $TMPFILE
sed -i 's/\///g' $TMPFILE
sed -i 's/\+//g' $TMPFILE
sed -i 's/\=//g' $TMPFILE
cat $TMPFILE; rm -f $TMPFILE
}
PASS = $(eval makepass)Huzzah! Once the account setup is done, all I do is echo $PASS so that the SysAdmin (me) can provide it to the end user.
echo $PASS | passwd --stdin NewUser
Until next time and as Richard Stallman says, "Happy hacking, folks."