Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add user script

Status
Not open for further replies.

dbase77

Technical User
Apr 23, 2002
591
IE
Hi all,

I have about 200+ user need to be added to our solaris 8 (sparc). I know I can use admintool but it will takes sometime to finish off. I want to create some sort of shell script that will accept username from a file. My problem is, how do I go about the password? The temporary password is $username1 and in the script I will force user to change password on the next login. Anybody out there could help me on how to add password without user interaction?

Thank you in advance.

regards,
Feroz
 
Only the first eight characters of a password are significant.

To create the password field in /etc/shadow do the following:

[tt]echo passwordAB | /usr/lib/makekey[/tt]

where password are the first eight characters of the password and AB are two randomly generated alphanumeric characters (you'll see these end up on the beginning of the generated key).

You can then use sed or something to insert it into the /etc/shadow file for the correct user. Annihilannic.
 
If I were in your shoes, I would use a script like the following:

#!/bin/ksh -x
UID=1000
FILE=/tmp/userlist
cp /etc/shadow /tmp/shadow
for i in `cat $FILE`
do
useradd -u $UID -g sys -m -d /export/$i $i
echo $i::12067:::::: >> /tmp/shadow
let UID=UID+1
done
cp /tmp/shadow /etc/shadow

As you can see, it would be easy to be able to specify different groups, home dirs, etc. The only difference I think in what you are asking is the default password is blank. When the user signs on, it makes them change the password, and won't let them sign on until they do, but they don't have to have a password to sign on and change it. This would probably be the simplest way of doing it.
You will want to change a password, then look at that user in /etc/shadow to get the 3rd field value on the day you run this. Today it will be 12067, tommorow is should be 12068, etc.

Will
 
Hi,

Thank you for replying. It's seem a bit tricky to play around shadow file. I found a way not to touch shadow file at all. After useradd, I just do passwd -d -f username. This will empty the password and force user to change it on next login.

regards,
feroz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top