Notes: Migrate Linux users to another Linux server
The PLAN: Migrate from Debain 5 to CentOS7, and avoid manually recreating user accounts or generating new passwords. Sounds easy right? Actually, it was and wasn’t as time consuming as I anticipated or took a lot effort to get all the user accounts including the host directory over to the new server.
I outlined the steps in gist below:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Setup UID filter limit | |
export UGIDLIMIT=500 | |
#copy /etc/passwd accounts to /opt/move/passwd.mig using awk to filter out system account | |
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /opt/move/passwd.mig | |
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /opt/move/group.mig | |
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd \ | |
| tee - |egrep -f - /etc/shadow > /opt/move/shadow.mig | |
cp /etc/gshadow /opt/move/gshadow.mig | |
# | |
scp -r /opt/move/* [email protected]:/path/to/location | |
mkdir /root/newsusers.bak | |
cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak | |
cd /path/to/location | |
cat passwd.mig >> /etc/passwd | |
cat group.mig >> /etc/group | |
cat shadow.mig >> /etc/shadow | |
/bin/cp gshadow.mig /etc/gshadow | |
#move home directory over ssh (tar to preserve ownership and permissions) | |
ssh [email protected] "tar czvpf - /home" | tar xzpf - -C / | |
FYI: Linux is awesome! :D