Notes: Migrate Linux users to another Linux server

By

The Problem

I have a Debian 5.0.4 virtual machine that's no longer supported and my shop is pretty much a CentOS ecosystem. The server is primary use for sFTP with over 250 user accounts.

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:

#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 /
view raw gistfile1.txt hosted with ❤ by GitHub

FYI: Linux is awesome! :D