How to Migrate User from One Linux System to Fresh installed new Linux System
How to Migrate Linux User from Old system to new Linux system :
You can migrate users from old Linux server to new Linux server with standard commands such as tar, awk, scp and others. In my Case, I'm using Ubuntu 16.04 LTS Server
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 ageing information.
* /etc/group – defines the groups to which users belong
* /etc/gshadow – group shadow file (contains the encrypted password for group)
* /home – All Users data is stored here.
Now reboot the system; when the Linux comes back, your user accounts will work as they did before on old system:
You can migrate users from old Linux server to new Linux server with standard commands such as tar, awk, scp and others. In my Case, I'm using Ubuntu 16.04 LTS Server
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 ageing information.
* /etc/group – defines the groups to which users belong
* /etc/gshadow – group shadow file (contains the encrypted password for group)
* /home – All Users data is stored here.
We have to back up all the above directories from Old system to New system.
Old System's Command: Run the following commands on the Old system.
Step 1- Create a Backup directory to keep all the files in it so we can copy this directory to new linux system.
root@Server1:~# mkdir /move
Step 2- Setup UID filter limit: Default is 1000 and upper limit is 29999 (/etc/adduser.conf). You can review this setting in this file.
root@Server1:~# export UGIDLIMIT=1000
Step 3- Copy /etc/passwd accounts to /move/passwd.mig using awk to filter out system account (i.e. only copy user accounts)
root@Server1:~# export UGIDLIMIT=1000
Step 4- Copy /etc/group file:
root@Server1:~# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > move/group.mig
Step 5- Copy /etc/shadow file:
root@Server1:~# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > move/shadow.mig
Step 6- Copy /etc/gshadow (rarely used):
root@Server1:~# cp /etc/gshadow move/gshadow.mig
Step 7- Make a backup of /home root@Server1:~# tar -zcvpf move/home.tar.gz /home
Step 8- Copy Backup file to New Linux System:
root@Server1:~# scp -r move/ user_New_server@New_Linux_IP_address:/New_system_Path
New System's Command: Run the following commands on the New system.
Step 9-
First, make a backup of current users and passwords:root@Server2:~# mkdir /newusers_backup
root@Server2:~# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /newsusers_bak
Step 10- Restore password, group etc backup file on New Linux system.
root@Server2:~# cd /backup_directory
Now run the following commands to restore users and their password.
root@Server2:~/resotre/move/home# cat passwd.mig >> /etc/passwd
root@Server2:~/resotre/move/home# cat group.mig >> /etc/group
root@Server2:~/resotre/move/home# cat shadow.mig >> /etc/shadow
root@Server2:~/resotre/move/home# cat gshadow.mig >> /etc/gshadow
root@Server2:~/resotre/move/home# cp --recursive user1 user2 user3 user4 user5/ /home/
Step 11- Reboot server
root@Server2:~/resotre/move/home# reboot
All the users have been migrated to the New Linux System successfully.