Skip to content

Instantly share code, notes, and snippets.

@lovellfelix
Last active September 26, 2018 04:33
Show Gist options
  • Save lovellfelix/9b7181b218ab02b4314e7ccd0194bbe2 to your computer and use it in GitHub Desktop.
Save lovellfelix/9b7181b218ab02b4314e7ccd0194bbe2 to your computer and use it in GitHub Desktop.
Migrate Linux users to another server
#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 /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment