Move User Accounts From Linux Server To Another Linux server

User Account Move

In Linux, user administration is very important because every process in Linux is owned by a user. Users can be people, accounts tied to physical users or accounts which exist for specific application. Linux user can be divided to two types, one is system users and another one is normal user or application users. The system user has default ID values 0 to 499 where normal user has ID value 500 to 60,000. We rarely upgrade OS and HW and we will migrate data from one server to another, but in some cases we need to move users also. While moving user accounts form one server to another server, you have to move user account related files also which is given below.

First, we have to understand user account related configuration files.

• /etc/passwd contains information about the user.
• /etc/passwd contains information about the group.
• /etc/shadow contains encrypted password for the user.
• /var/spool/mail contains user mails are stored in this file.
• /home/user contains users home directory, hence it may contains user data.

The above files are important while moving users from one server to another, hence we need backup the above files.

[[email protected] ~]#mkdir accountbackup
[[email protected] ~]# export UGIDLIMIT=500
[[email protected] ~]# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/accountbackup

Above command will copy the /etc/passwd file filtered accounts to /etc/accountbackup/ passwd.olds.

Similarly, copy the selected groups in /etc/group file:

[[email protected] ~]# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group >

Now copy the shadow file:

[[email protected] ~]# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/accountbackup/shadow.old

Now, backup the users home directory and users mails:

[[email protected] ~]# tar -zcvpf /root/accountbackup/home.tar.gz /home

Now, backup of the users mails:

[[email protected] ~]# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail

Now you have taken the user account related files. Copy all the data in a pen drive or a new server by scp command. Before starting the migration to new server, make sure to backup all user related files in the new server.

Restore the data into the new server.

[[email protected] ~]# # cat passwd.old >> /etc/passwd
[[email protected] ~]# # cat group.old >> /etc/group
[[email protected] ~]# # cat shadow.old >> /etc/shadow
[[email protected] ~]# # /bin/cp gshadow.old /etc/gshadow

Similarly, restore the users data as well as the users mails to the new server.

[[email protected] ~]# tar -zxvf /path/to/location/home.tar.gz
[[email protected] ~]# tar -zxvf /path/to/location/mail.tar.gz

Bobbin Zachariah 2:10 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.