Operating System - HP-UX
1825770 Members
2002 Online
109687 Solutions
New Discussion

Users/groups copying to another server..

 
Avarsang Shankar
Occasional Contributor

Users/groups copying to another server..

Does anyone know how to copy all users/groups and their attributes from one system to another instead of copying one user at a time ? If I have to write a script, does anyone know which files need to be copied along with password info. The server is a trusted system.
9 REPLIES 9
Patrick Wallek
Honored Contributor

Re: Users/groups copying to another server..

I have done this fairly successfully by copying the entire /tcb directory structure and the /etc/passwd and /etc/group files. YOu might want to be careful of system accounts like root, but I've never had any problem.

You may also want to copy /home, or where ever the users home directories are, over to the new machine as well.
RAC_1
Honored Contributor

Re: Users/groups copying to another server..

The trusted system keep all data in /tcb directory. If all users on both systems same? You can move whole this directory to another server.
There is no substitute to HARDWORK
Michael Schulte zur Sur
Honored Contributor

Re: Users/groups copying to another server..

Hi,

I agree with Patrick. I have another thread with the same solution, but I lost it. :-(

Michael
Avarsang Shankar
Occasional Contributor

Re: Users/groups copying to another server..

Thank you for all the responses. Is there any command to check the integrity/consistency check once I copy to another server? (like in AIX)
Patrick Wallek
Honored Contributor

Re: Users/groups copying to another server..

There sure are:

To check the passwd file consistency:

# pwck

To check the passwd file and the /tcb structure:

# pwck -s
or
# authck -p

To check the group file consistency:

# grpck
Steven E. Protter
Exalted Contributor

Re: Users/groups copying to another server..

I edit a copy of /etc/passwd from the source server, null out the passwords and copy it as /root/newusers to the new one.

Then cat /root/newusers >> /etc/passwd

Same thing for any new groups.

Then check consistency as noted in prior answers.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Scott J. Showalter
Frequent Advisor

Re: Users/groups copying to another server..

Steven E Protter,

Why is it that you null out the passwords when copying the file to a new host?
In a world without fences, who needs Gates?
Juergen Tappe
Valued Contributor

Re: Users/groups copying to another server..

Here a poissible script doing your need user per user and checking each ... :
it should run on the destination server
I assume remsh between the 2 servers otherwise use ssh and scp:

REMHOST=
USERS=$(remsh $REMHOST pwget | awk '{print $1}')

for i in $USERS
do
if pwget -n $i > /dev/null 2/dev/null
then
true # dont add this one as it exists already
else
PWLINE=$(rmesh $REMHOST pwget -n $i)
echo $PWLINE >> /etc/passwd
GRP=$(echo "$PWLINE" | cut -d: -f4)
if grget -g $GRP > /dev/null 2> /dev/null
then
true # dont add it line to group file
else
GRPLINE=$(remsh $REMHOST grget -g $GRP)
echo $GRPLINE >> /etc/group
fi

FIRST_CHAR=$(echo $i | cut -c1)
rcp -p $REMHOST:/tcb/auth/file/$FIRST_CHAR/$i /tcb/aauth/file/$FIRST_CHAR/$i

# copy content of hoemdir if you like
HDIR=$(remsh $REMHOS pwget -n $i | cut -d: -f6)
if [ ! -d $HDIR ]
then
mkdir -p $HDIR
rcp -p $REMHOST:$HDIR $HDIR
fi
fi # end of if pwget ....
done

If I didnt made typos and didnt mixed up the fields of passwd file or tcb dirs it should run.
I am not 100% sure if the rcp realy keeps user/group of the files. In one of the directios they might get resetted to root.
Better you try that before running the whole script.
Working together
Juergen Tappe
Valued Contributor

Re: Users/groups copying to another server..

Sorry, found one mistake
replace 2nd line with
USERS=$(remsh $REMHOST pwget | cut -d: -f1)

instead of copying the complete homedirectories you could copy over just .profile or other single files.

You might also include a chown $i:$GRP $HOME
after the mkdir ... line.

regards
Juergen
Working together