Sep 13, 2010

Migrate user accounts from old Linux server to new Linux server

Migrate user accounts from old Linux server to new Linux server


RedHat Enterprise Linux



Migrate user accounts from old Linux server to new Linux server



The below procedure explains how to migrate users from old Linux server to new fresh installation.


Required files and directories:

            The following files and directories are required for Linux user account management

/etc/passwd – Contains various information about each user account

/etc/shadow – Contains the encrypted password information for user’s accounts

/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 home directory and data is stored here

All these files and directories are need to copy from old server to new server.



a)      Users that are added to the Linux system always start with UID and GID values of as specified by Linux distribution or set by admin. In RHEL default is 500 and maximum limit is 65534.


b)      The home directory of all the users is kept in /home. If there are different locations, it is mandatory to take separate backup of each location.

c)       There are enough space in /migrate file system to hold the backup of user’s directories.


Old Server side Configuration:


1)      Create a tar ball of the users home directory and mails

# mkdir /migrate

# cd /migrate

# tar –czvpf home.tar.gz /home

# tar –czvpf mail.tar.gz /var/spool/mail


2)      Now copy all the required user account management files from the old server

# export UGIDLIMIT=500


# awk –v LIMIT=$UGIDLIMIT –F: ‘($3>=LIMIT) && \               ($3!=655354)’ /etc/passwd > /migrate/passwd.old


# awk –v LIMIT=$UGIDLIMIT –F: ‘($3>=LIMIT) && \ ($3!=655354)’ /etc/group > /migrate/group.old


# awk –v LIMIT=$UGIDLIMIT –F: ‘($3>=LIMIT) && ($3!=65534) \ {print $1}’ /etc/passwd | tee - | egrep –f - /etc/shadow \ > /migrate/shadow.old


# cp /etc/gshadow /migrate/gshadow.old


The above three commands to extract only normal user details from /etc/passwd, /etc/group,  /etc/shadow and /etc/gshadow from UID/GUID from 500 (Refer the assumptions).


3)      Copy all the files inside the /migrate to the new server using scp or pendrive


New Server side Configuration:


4)      Take the backup of the user account management files in the new server

# mkdir /backup

# cp /etc/passwd /etc/group /etc/shadow /etc/gshadow /backup


5)      Copy all the files copied from the old server in new server within /new directory

# mkdir /new

# cd /new


6)      Now restore all the files

# cat passwd.old >> /etc/passwd

# cat group.old >> /etc/group

# cat shadow.old >> /etc/shadow

# cp gshadow.old /etc/gshadow

# chmod 0400 /etc/gshadow

# chown root:root /etc/gshadow


7)      Now copy and extract the users home directory and mail backups

# cd /

# tar –zxvf /new/home.tar.gz

# tar –zxvf /new/mail.tar.gz


8)      Reboot the server and check

# init 6





No comments: