SUMMARY: How to create password in the script? Version 2

From: Stephanie C <>
Date: Fri May 09 2008 - 17:07:28 EDT
I wrote the following script to create multiple user accounts that I would
like to share with the group (no expect needed). This script will do the
1. Create user account
2. Reset/unlock the account (remove *LK* in the shadow file for that
3. Create a encrypted password as 'pass123'. Field: 'n${ACCT}' is just key
generated (you can put anything in this field)
4. Put the password into /etc/shadow for each user account when created.

# 05/14/2006
# Author: Stephanie
# This script creates multiple user accounts using the username text file.

echo "Home directory (/export/home/its): \c"
read DIR
echo "Belong to GROUP (oracle): \c"
read GROUP
echo "Account name text file (/tmp/acctname.txt): \c"
while read ACCT
  useradd -d ${DIR}/${ACCT} -g ${GROUP} -s /bin/ksh -m -k /etc/skel/ ${ACCT}
  passwd -u ${ACCT} # unlock password and set to null
  PW=`perl -e '$x=crypt('pass123','n${ACCT}'); print $x'`
  perl -pi -e s/${ACCT}:/${ACCT}:${PW}/g /etc/shadow
done < ${USERFILE}

exit 0

On Wed, May 7, 2008 at 10:16 AM, Stephanie C <> wrote:

> Thank you very much for all the responses. Here are couple options:
> - Use 'expect'. I have to learn this.
> - Use the following syntax within the script right after the 'useradd' line
> to add the password into /etc/shadow file:
>  echo ${useracct}:`perl -e '$x=crypt('password','n${useracct}'); print
> $x'`:13798:::::: >> /etc/shadow
> This works fine, but the shadow file has two lines for one user. One line
> is the locked password and another has the added password line. I have to
> edit the shadow file to remove the locked password line. This is no can do.
> - Put a following line in the script  right after the useradd line:
> passwd -u ${useracct} (this to unlock the account with a null password,
> users need to set the password at first login). I will go with this option
> for now.
> Thanks.
> Stephanie
> I have to create hundreds and hundreds (thousands) of user accounts on our
> solaris 10 servers. I have created a script to do so. The problem is, I
> don't want to set the password for these users by typing 'passwd' command
> for every one of them (take forever to do this). I know Linux's useradd
> command has an option '-p' to set the password, but not solaris. Is there a
> way to create a default password in the script when create user account?
> Here is my the useradd script:
> #!/usr/bin/ksh
> # 05/14/2006
> # Author:
> # Script:
> #
> DIRECT="/export/home/its"
> GROUP="staff"
> while read useracct
> do
>   useradd -d ${DIRECT}/${useracct} -g ${GROUP} -s /bin/ksh -m -k /etc/skel/
> ${useracct}
>  * passwd ${useracct} < /dmp/userpassfile.txt (NOT WORKING, IT PROMPTS FOR
> done < /dmp/useraccount.txt
sunmanagers mailing list
Received on Fri May 9 17:08:22 2008

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:44:11 EST