I've used this to copy over accounts. (But not mailboxes.) I don't remember where I found it, I just copied it over and saved itform My own
Dynamic DNS Server..
ALWAYS TEST ANYTHING LIKE THIS BEFORE DOING IT FOR REAL!
Quote:
To copy accounts from Box1 to Box2, do the following. We need to copy the accounts from /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow, as well as the users' home and mail directories. On Box1, as root, do the following
mkdir /root/move
Set a UID limit. The default non system accounts on RH based systems begin at UID 500 and go up to 65534. (In Debian based systems, it's 2999.) We want to avoid copying over the system accounts.
export UGIDLIMIT=500
Copy /etc/passwd and /etc/group, using awk to filter out accounts with UID's under 500
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
The following two lines are one command and should be typed on one line.
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd |tee - |egrep -f -
/etc/shadow > /root/move/shadow.mig
Copy gshadow as well--though rarely used, it won't hurt
cp /etc/gshadow /root/move/gshadow.mig
Tar and compress home and mail directories
tar zcvpf /root/move/home.tar.gz /home
tar zcvpf /root/move/mail.tar.gz /var/spool/mail
Copy the move directory to the new machine. Using scp is fine
scp -r move Box2:
On Box2 be sure to make a backup first, in case anything goes wrong. The ideal situation is one where Box2 is a brand new intall and no non-system accounts have been created, but things can easily go wrong.
mkdir /root/newusers.bak
cp -r /etc/passwd /etc/shadow /etc/group /etc/gshadkow /root/newusers.bak
Assuming that you've copied the move directory to /root on Box2 and that you are now in /root, just cd move as in the instructions below. If you've put the move directory somewhere else on Box2 or if you are in another directory there, adjust the path accordingly and replace "move" in the below commands with the path to the move directory.
cd move
cat passwd.mig >> /etc/passwd
cat group.mig >> /etc/group
cat shadow.mig >> /etc/shadow
cp gshadow.mig /etc/gshadow
(We're not as concerned about gshadow. It contains passwords for groups (rather than individuals) and probably won't affect anything.)
IMPORTANT! Note that we're doing cat >> and NOT cat >. We're appending entries to /etc/passwd, /etc/shadow and /etc/group, not overwriting them. (If you make the mistake and do cat > you can always replace the original file from the /root/newusers.bak directory that you made earlier.)
Now copy and extract the home and mail directories
cd /
tar zxvf /root/move/home.tar.gz
tar zxvf /root/move/mail.tar.gz
Reboot and accounts should be successfully moved to the new system.