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



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
following:
1. Create user account
2. Reset/unlock the account (remove *LK* in the shadow file for that
account)
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.

#!/usr/bin/sh
# 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"
read USERFILE
while read ACCT
do
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 <stepchung@xxxxxxxxx> 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

QUESTION:
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: user_add.sh

#

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
PASSWORD)*

done < /dmp/useraccount.txt
_______________________________________________
sunmanagers mailing list
sunmanagers@xxxxxxxxxxxxxxx
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



Relevant Pages

  • Re: Is it possible to reset "pwdLastSet" attribute to certain date
    ... Anyone able to review the script I treid why not working? ... when I checked the attribue of the PwdLastset nothing being ... Dim strContainer, strDNSDomain ... ' Loop through OU=, resetting all user accounts ...
    (microsoft.public.windows.server.active_directory)
  • Re: objUser.SetInfo "general access denied error"
    ... I don't see where you bind to objOU. ... the script a few times during troubleshooting, it is also possible the user ... 'This script creates AD user accounts from a CSV file ... Const ADS_PROPERTY_UPDATE = 2 ...
    (microsoft.public.scripting.vbscript)
  • Script to create AD and Exchange user account by copying existing account?
    ... copying user accounts to create new user accounts. ... Since I'm running Exchange 2007, ... I'd like the ability to create a script and pass in some ...
    (microsoft.public.windows.server.scripting)
  • AD child domains
    ... I'm trying to modify a vbs script that I found on the internet to show the ... Exchange mailbox quota values for user accounts. ...
    (microsoft.public.scripting.vbscript)
  • SUMMARY: How to create password in the script?
    ... Use the following syntax within the script right after the 'useradd' line ... but the shadow file has two lines for one user. ... I have to create hundreds and hundreds of user accounts on our ...
    (SunManagers)