LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Moving passwd file to new server (https://www.linuxquestions.org/questions/linux-newbie-8/moving-passwd-file-to-new-server-344720/)

rtcary 07-19-2005 02:11 PM

Moving passwd file to new server
 
If one has 500 users on a server and need to move them to another newly installed server that just has root, the one new user (GUID = 500) plus all of the entries with a GUID < 500, what is the best way to copy the users to the new computer?

nixcraft 07-19-2005 02:47 PM

Create tar file of /etc/passwd /etc/shadow and /home directory + Mail directory. Then restore this tar file. Becareful about root password. Copy the file /etc (passwd + shadow) and rest to the /home and mail folder.

Tinkster 07-19-2005 03:04 PM

As root
Code:

awk -F: '$3 >= 500 {print}' /etc/passwd > ~/pwd.txt
awk -F: '{print $1}'  ~/pwd.txt | xargs -i grep {} /etc/shadow > ~/shd.tx
scp ~/pwd.txt user@server2:.
scp ~/shd.txt user@server2:.

On the second server as root:
Code:

cat ~user/pwd.txt >> /etc/passwd
cat ~user/shd.txt >> /etc/shadow

OIFS=$IFS; IFS=: \
while read name passwd uid gid fullname home shell \
do \
  mkdir "$home" \
  chown "$uid":"$gid"  "$home" \
done < ~user/pwd.txt \
IFS=$OIFS

The red bit is untested, but it should work ;)


Cheers,
Tink

rtcary 07-19-2005 09:42 PM

Thank you for the awk script. awk is one of those Linux/unix treasures I have not explored (partially because it is quite intimidating).

Tinkster 07-19-2005 10:06 PM

Welcome - were you brave enough to test the
other bits? :}

chrism01 07-20-2005 01:58 AM

Here's a nice awk intro, with further links :)
http://www.oracle.com/technology/pub...laney_awk.html


All times are GMT -5. The time now is 04:17 AM.