Monday, February 21, 2011

Migrate user accounts from old Linux server Fedora to a new CentOS Linux server including mails and passwords.

Migrate user accounts from old Linux server(Fedora 13) to a new Cent OS Linux server including mails and passwords.

Why do I write this blogpost?
I'm using Sendmail + Squirrelmail + Dovecot since 2002 under Fedora Linux. But now i must switch my System to CentOS (orRHEL) 'cos my squirrel mail change password plugin was not work. Got a lot of trouble installing SuSE, Fedora 14 & Ubuntu. After testing those OS's I found that CentOS is the best solution for this.

I AM NOT RESPONSIBLE FOR ANY DAMAGES INCURRED DUE TO ACTIONS TAKEN BASED ON THIS DOCUMENT..........

What do i need to migrate?
1. Time
2. A lot of Coffee
3. Some Cigaretts (optional)
4. Take your wife/family out for a night or weekend

First login to our Mailserver(Fedora 13)

Create a directory
# mkdir /root/newusers.bak
# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newusers.bak
# cd /root/newusers.bak
# mv passwd passwd.mig
# mv group group.mig
# mv shadow shadow.mig

(rarely used)
# cp /etc/gshadow /root/newusers.bak/
# mv gshadow gshadow.mig

Then delete entries from top (root) to userID 500 in every above 3 files. This bring our Useraccounts, passwords & their groups.

Use rsync, scp or usb pen or tape to copy /root/newusers.bak to a new Linux system.(CentOS)

# scp -r /root/newusers.bak/* user@172.16.1.254:/root/sandun/newusers/

Now login to our New mail server (CentOS)

First, make a backup of current users and passwords:
# mkdir /root/users.bak
# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/users.bak

Now restore passwd and other files in /etc/
# cd /root/sandun/newusers/
# cat passwd.mig >> /etc/passwd
# cat group.mig >> /etc/group
# cat shadow.mig >> /etc/shadow

Now copy and extract /home/ and /var/mail/ to new Server's /home/ & /var/mail/

<<<< Change the user ID to 500 if you migrate Suze Linux
vi /etc/login.pref
UID_MIN 500 >>>>

# rsync -ave ssh /home/ root@172.16.1.254:/home/
# rsync -ave ssh /var/mail/ root@172.16.1.254:/var/mail/

Single user(ex:- sandun)
# rsync -ave ssh /home/sandun root@172.16.1.254:/home/
# rsync -ave ssh /var/mail/sandun root@172.16.1.254:/var/mail/

Voila, now login to the new system using old server username and password.....

+++++++++++++++++++++++++++++++++
(we can filter out system account using 'awk')
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig

source: http://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/

No comments: