SUMMARY: How to create password in the script? Version 2
- From: "Stephanie C" <stepchung@xxxxxxxxx>
- Date: Fri, 9 May 2008 14:07:28 -0700
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
- Prev by Date: Display problem on Dual-monitor (Sun/Linux problem)
- Next by Date: Lost+Found
- Previous by thread: Display problem on Dual-monitor (Sun/Linux problem)
- Next by thread: Lost+Found
- Index(es):
Relevant Pages
|