I'm trying to add users via a script using the following command.
The result is that I am only getting a portion of the encrypted password
in the /etc/shadow file. I've tried lots of variations on using ' hard quotes with no luck.

Any help? Thanks.

USER=newuser
PASSWD=`openssl passwd -1 $USER`

echo $PASSWD returns
$1$2DIVvhnL$5aSr5G1O17cQXdG8HshOu.

CMD="useradd -p `openssl passwd -1 $USER` $USER"
or
CMD="useradd -p $PASSWD $USER"

results in the following in /etc/shadow:
newuser:DIVvhnLaSr5G1O17cQXdG8HshOu.:13656:0:99999:7:::

The $1$2 portion of the passwd has been dropped. If there are other special characters in the password string, such as $ or / then the password gets truncated at those points as well.

I've tried variations like

PASSWD=`openssl passwd -1 $USER`
CMD="useradd -p $PASSWD $USER"
CMD="useradd -p ${PASSWD} $USER"

etc.

Thanks
Andrew

Ah, This works

CMD="useradd -p '`openssl passwd -1 $USER`' $USER"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.