Nasser Heidari

2010-07-20

Move user accounts from old Linux server to a new Linux server

Filed under: Linux — Nasser Heidari @ 16:37

Following files/dirs are required for traditional Linux user management:

/etc/passwd – contains various pieces of information for each user account
/etc/shadow – contains the encrypted password information for user’s accounts and optional the password aging information.
/etc/group – defines the groups to which users belong
/etc/gshadow – group shadow file (contains the encrypted password for group)
/var/spool/mail – Generally user emails are stored here.
/home – All Users data is stored here.

————-
Backup Routine:
————-

# mkdir /root/move/
# export UGIDLIMIT=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
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow >  /root/move/shadow.mig
# cp /etc/gshadow /root/move/gshadow.mig
# tar -zcvpf /root/move/home.tar.gz /home
# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail

————- Move Backup Files to New Linux Server: ————-

scp -r /root/move/*  nasser@linax.wordpress.com:/var/tmp

————- Restore : ————-

# mkdir /root/newsusers.bak

# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak

# cd /var/tmp

# cat passwd.mig >> /etc/passwd

# cat group.mig >> /etc/group

# cat shadow.mig >> /etc/shadow

# /bin/cp gshadow.mig /etc/gshadow

# cd /

# tar -zxvf /var/tmp/home.tar.gz

# tar -zxvf /var/tmp/mail.tar.gz