I'm in the process of making a bash script to automate adding a user. My password always have pattern, so I am setting that to a variable then... (this is where I am stuck -encrypting-). I found this post but that talks about -stdin
which I don't want to use. Besides, I am asked for the password if I omit it anyway. So, how can I encrypt the password from my username automatically?
My script
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 <user>"
else
p=${1%.*}
p=$(echo $p | tr -d 'aeiou' | openssl passwd) $1
useradd -p $p $1
fi
EDIT: mkpasswd on CentOS doesn't seem to work like the one mentioned in the post I linked.
EDIT2: bash version is 4.1.2(1)-release
, if that matters.