LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-19-2005, 02:11 PM   #1
rtcary
Member
 
Registered: Dec 2004
Location: Petaluma, CA
Distribution: Centos 4 and RH 9
Posts: 47

Rep: Reputation: 15
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?
 
Old 07-19-2005, 02:47 PM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
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.
 
Old 07-19-2005, 03:04 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
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

Last edited by Tinkster; 07-19-2005 at 03:05 PM.
 
Old 07-19-2005, 09:42 PM   #4
rtcary
Member
 
Registered: Dec 2004
Location: Petaluma, CA
Distribution: Centos 4 and RH 9
Posts: 47

Original Poster
Rep: Reputation: 15
Thank you for the awk script. awk is one of those Linux/unix treasures I have not explored (partially because it is quite intimidating).
 
Old 07-19-2005, 10:06 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Welcome - were you brave enough to test the
other bits? :}
 
Old 07-20-2005, 01:58 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question about /etc/passwd file hongxing Linux - Software 2 11-30-2005 10:47 AM
how to filter output from passwd file mussussu Linux - General 2 11-28-2005 04:17 PM
Where can i find the passwd file? alice95089 Linux - Software 3 04-06-2005 10:01 PM
Moving /etc/passwd and /etc/shadow john8675309 Linux - Software 1 01-24-2005 08:44 PM
/etc/passwd file wedgeworth Linux - Software 1 10-09-2003 12:53 PM


All times are GMT -5. The time now is 07:40 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration