1833883 Members
1825 Online
110063 Solutions
New Discussion

Re: User creation !!

 
Whitehorse_1
Frequent Advisor

User creation !!

Gentlemen,,(Doubt in Shell script)

Is ther anyways, I can create username with passwd inputs(non-interactive) through shell script.

Thxs, WH
Reading is a good course medicine for deep sleep !!
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: User creation !!

Hi:

You can create a password with 'crypt' and update the '/etc/passwd' file accordingly for the user(s) in question.

Regards!

...JRF...
Calandrello
Trusted Contributor

Re: User creation !!

Friend if you only desire to have a user, but that it does not effect login in the SO she creates a usuario: useradd username and blocks the usuario: passwd - l username
Whitehorse_1
Frequent Advisor

Re: User creation !!

Hi JRF,

My requirement is to create 15 users across 50 servers. So i prepared a script will all inputs. But I couldnt set my default passwd through the script.

Anyways to do this.. WH
Reading is a good course medicine for deep sleep !!
Tim Nelson
Honored Contributor

Re: User creation !!

I have a script that creates the commands from a master file. That file is then distibuted to the proper server. I log into each server and run the script which creates all the user accounts. With this exception. The script runs modprpw -x on the account to gen a temp password for the user. This may be different from what you are looking for.

One thought if using HPUX Trusted system is to use sed to replace the /tcb/files/auth/X/user encrypted password entry or just copy the file from the already setup entry on another host.
Peter Godron
Honored Contributor

Re: User creation !!

Doug O'Leary
Honored Contributor

Re: User creation !!

Hey;

/usr/sam/lbin/useradd.sam accepts a -p option for supplying an encrypted password. Unlike the regular useradd (to which it's soft-linked, figure that one out), it doesn't automatically create the home directories so you'll have to use other steps for that.

1. Manually add a user and set the password to what you want as the default.

2. Obtain that password and store it in your script.

3. Inline function (w/assumptions on what your datafile looks like)

cat ${file} | while read user pwd uid gid Groups gecos home shell
do
/usr/sam/lbin/useradd.sam -p ${pwd} \
-u ${uid} \
-g ${gid} \
-G ${Groups} \
-c "${gecos}" \
-s ${shell} \
-d ${home} ${user}
mkdir -p ${home}
cp /etc/skel/.[A-z]* ${home}
chown -R ${user}:${gid} ${home}
done

Note that you'll want to protect this script as you would the shadow password file - ie root read only, in a directory structure that is accessible only by root.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html