Hello, sry my delay to reply.
The $OPTARG when echoed, displays this value:
bashapptF0cp0wzQYGuQRuknpC8qG7U0
when the MD5 given on the command line is this:
$1$0apptF0c$5p0wzQYGuQRuknpC8qG7U0
I did some changes to the script today, and then I found a work-around to the problem. However I had to specify the '' quotes on the command line arguments, e.g:
./useradd.sh -d /home/kkrayher -s /bin/ksh -S -md5 '$1$0apptF0c$5p0wzQYGuQRuknpC8qG7U0'
however this is something that I wanted to avoid (if possible).
The changes I've done trying to format the string into this format (\$1\$) inserting a \ before any $, is to be used with sed, so I can write exactly the MD5 hash on the /etc/shadow file. On my past attempts, the result that I got into the shadow file was something like: "/etc/shadow xzjoe1:bashapptF0cp0wzQYGuQRuknpC8qG7U0:0:1:30:7:::".
LOL, I was not understanding WHY I could not login with the password that I generated using the "openssl passwd -1 password"!
My objectives with this script are:
1. MD5HASH="$OPTARG" will store the MD5
2. I will used SED to replace the '$' by '\$' from the $MD5HASH variable.
3. I will input the formated $MD5HASH into the shadow file.
Step 1/2:
Code:
if [ -n "$SECURE" ] ; then
if [ "$OS" = "Linux" ]; then
PASSHASH=$(echo $MD5HASH|$SED 's|[$]|\\$|g')
else
PASSHASH=$CRYPTHASH
; fi
else
PASSHASH="uJIq6tah3ww7s"
if [ "$OS" = "Linux" ]; then PASSHASH="\$1\$QXBUI7di\$NwC5aBYM9TgHC03mvawSb1" ; fi
fi
Step 3:
Code:
if [ -r $ETCSHADOW ] ; then FILE=$ETCSHADOW
else FILE=$ETCPASSWD
fi
case $OS in
HP-UX) $SED "s/$UNAME:\*/$UNAME:$PASSHASH/" $FILE > $FILE.$$ ;;
Linux) $SED "s/$UNAME:\!\!/$UNAME:$PASSHASH/" $FILE > $FILE.$$ ;;
*) $SED "s/$UNAME:\*LK\*/$UNAME:$PASSHASH/" $FILE > $FILE.$$ ;;
esac
fi
$CP -p $FILE.$$ $FILE
$RM $FILE.$$
So, at this point the question I've for you is:
- Is there a way to avoid having to use the '' on this md5 hash on the command line? or is this something that must be used?
Thanks for your time,