Operating System - HP-UX
1832252 Members
2743 Online
110041 Solutions
New Discussion

copying users to new server?

 
SOLVED
Go to solution
Dan Matlock_1
Regular Advisor

copying users to new server?

Is there a quick way to copy the /etc/passwd & /home/* to a new server and generating active accounts on a NEW server? Seems I have read about this in the past, and would like to do this on a brand new replicated server. Both systems are trusted.
11 REPLIES 11
Tim Nelson
Honored Contributor

Re: copying users to new server?

Hey Dan,

there are a couple ways but none at the snap of the fingers.


idea 1) write a script to extract the password entries and create the useradd commands, tar the home directory, and rcp these file to the new server (as some other user other than root). On the new server execute this script as the root user.
Alan Meyer_4
Respected Contributor

Re: copying users to new server?

you could also setup NIS/LDAP and use an nfs shared filesystem as the logon directory location
" I may not be certified, but I am certifiable... "
Steven E. Protter
Exalted Contributor

Re: copying users to new server?

If your system is not trusted you can try and copy a portion of the /etc/passwd file and it might work.

Generally, we used a script to add users.

You can try to copy the /tcb directory to the new server, making sure to ommit system accounts like root.

It will probably fail.

I recommend adding the users by script and setting and distributing passwords. You can go in afterwards into /etc/passwd and alter the numeric users to match what they were on the old system.

The /home directory, I recommend merely tarring it up and transferring it. In conjunction with my other recommendations, its likely that at least file ownership will be perserved, if not fully meeting your question objectives.

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
Mel Burslan
Honored Contributor

Re: copying users to new server?

after copying the /home with the tool of your choice, ftp/scp/cpio or whatever else, you will need to copy /tcb/files/auth/* in addition to the /etc/passwd.

After all is said and done, you need to run the command:

pwconv

to resynchronize the passwords with the trusted computing database.

You may end up with some locked accounts at the end of this, so keep a few root login windows open to unlock them if you run into this situation.

hope it helps
________________________________
UNIX because I majored in cryptology...
Ranjith_5
Honored Contributor

Re: copying users to new server?

Hi Dan,

Best metod is using a script. copying the password file should work, but generate the home directory of the users accordingly.
see the script in the following post. But this is for a trusted system.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=952123

Regards,
Syam

Jeff Carlin
Frequent Advisor

Re: copying users to new server?

We did something like this when moving from an old K class to an A500.

Use the /etc/passwd file if you are not trusted, otherwise make a file from the /etc/passwd and the files in /tcb/files/auth/? looks something like USER:PW_HASH:UID:GID:NAME_TEXT:SHELL

Then you can write a script around the useradd.sam command to read from that file and add the user. The line to actually add the user would look something like this:

/usr/sam/lbin/useradd.sam -u ${UID} -p ${HASH} -g ${GROUP} -m -k /etc/skel -s ${SHELL} -c "${NAME}" ${USER}

Then you could copy the home dirs with a command similar to:

remsh {REMOTESYSTEM} "cd /home;tar cf - ." | (cd /home; tar xf -)

Test that last command... I typed it from memory and that usually isn't a good thing.

JC
Where wisdom is called for, force is of little use. --Of course, a hammer does wonders for relieving stress.
Paul Sperry
Honored Contributor

Re: copying users to new server?

I'd do this.

Copy the /etc/passwd file from the old server
to /somedir/userinfo on the new server

created a script like this.

cat /somedir/userinfo |while read line
do
USER=$(echo $line|awk '{FS=":";print $1}')
PASS=$(echo $line|awk '{FS=":";print $2}')
USERID=$(echo $line|awk '{FS=":";print $3}')
GID=$(echo $line|awk '{FS=":";print $4}')
INFO=$(echo $line|awk '{FS=":";print $5}')
HOME=$(echo $line|awk '{FS=":";print $6}')
SHELL=$(echo $line|awk '{FS=":";print $7}')
echo "Adding $USER"
useradd -u $USERID -g $GID -s $SHELL -c "$INFO" -o -m -k /etc/skel -d $HOME $USER
/usr/sam/lbin/usermod.sam -p`echo "$PASS"` $USER
done

Run the script and your done

Home dirs will be the same.
UIDs will be the same.
Shells will be the same.
Groups will be the same.
Passwords will be the same.
Even any comments will be the same.

Have fun
Paul Sperry
Honored Contributor
Solution

Re: copying users to new server?

$HOME $USER

Should be on the same line as the useradd command right after the -d
Dan Matlock_1
Regular Advisor

Re: copying users to new server?

great info, but should i scp the /etc/group file over from the old server prior to running this?
Mel Burslan
Honored Contributor

Re: copying users to new server?

if you have custome defined groups with users assigned to these groups as their primary group, yes I think you should be copying the group file as well. As a matter of fact, you need to copy the group file if you have anything other than the groups created by default at the system build time to prevent inconsistencies.

Make sure the destination system does not have group numbers any different than source system as this may throw off the existing accounts and files' with these kinds of group memberships. Proceed with care is the best advice under these circumstances.
________________________________
UNIX because I majored in cryptology...
Dan Matlock_1
Regular Advisor

Re: copying users to new server?

thanx great info, and trying the steps now.