Operating System - HP-UX
1827775 Members
2552 Online
109969 Solutions
New Discussion

Re: Automate user creation

 
Mohammed Ali_6
Occasional Contributor

Automate user creation

Is it possible to write an useradd script that will take input from an an existing passwd file? I am trying to replicate the users I have on one box to another seven boxes with the same user info. The script should be something like:

cat /etc/passwd | while read LINE
do
useradd option option
done

Not sure how to parse the passwd file to get the uid, gid, home etc.

Thanks in advance,

Ali
8 REPLIES 8
Biswajit Tripathy
Honored Contributor

Re: Automate user creation

awk -F: should work fine for getting uid, gid, home etc.
Something like

cat /etc/passwd | while read LINE
do
echo $LINE | awk -F: '{print $3, $4, $6}' | \
read -r gid uid home
useradd option option
do

- Biswajit
:-)
Rajeev  Shukla
Honored Contributor

Re: Automate user creation

If the requirement is to replicate the users, why not copy the /etc/passwd and /etc/group files accross to another system excluding the system logins like root, adm, lp etc..

And if the systems are trusted then copy the /tcb files or other option is to untrust the system first and then coppy passwd and group files.

Cheers
Rajeev
Mohammed Ali_6
Occasional Contributor

Re: Automate user creation

Rajeev,

The systems are trusted; So copying the password file and the /tcb directory to the other systems should do the trick? What about the user's password, would that be the same on the target server?

Thanks,
Ali
Rajeev  Shukla
Honored Contributor

Re: Automate user creation

Yes Mohammed, If the systems are trusted copying the /etc/passwd, /etc/group and /tcb will do the trick.
The users password are stored in /tcb/files/auth so all the password will remain as it was on the old system.

Cheers
Rajeev
lawrenzo
Trusted Contributor

Re: Automate user creation

Here is a bit of a " Curve ball"

Instead of replicating the accounts on the other servers have you though about configuring NIS / NIS +

This allows one account on the nis master and with the correct config you can have access to any other serve rin that domain.

We use that here in one of our networks and it works well.

HTH
hello
Mohammed Ali_6
Occasional Contributor

Re: Automate user creation

Thanks for the NIS suggestion. I am also for a centralized authentication server, but unfortunately NIS is against our corporate policy (don't ask me why, I don't get it either). We are however in the process of implementing a customized LDAP solution to authenticate against Active Directory. But until that completes, I gotta do this manually :(
Rajeev  Shukla
Honored Contributor

Re: Automate user creation

To have all the password on all the servers synced you can actually write a script which we have done.
This script simply runs from /etc/profile and copies the /tcb/files/auth/?/ to all the servers when he logs in. This way you can keep the password in sync on all the trusted systems till you work on ldap or NIS solution

Cheers
Rajeev
Bill Hassell
Honored Contributor

Re: Automate user creation

A note about NIS. The main reason it is a security risk is that it transmits plaintext passwords (and other data) over the network. NIS+ encrypts the data but it is not backward compatible and many systems cannot use NIS+. Most shops that need a central authentication method are using LDAP. Locally, the questions about NIS are not important if your users connect using telnet or 'r' commands such as remsh, rcp, rexec, or rlogin.


Bill Hassell, sysadmin