0

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

1
Contributor
1
Reply
2
Views
10 Years
Discussion Span
Last Post by ajcamp
0

Ah, This works

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.