Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askz/91fc3368691501ff0f4d2d838ec6b4f5 to your computer and use it in GitHub Desktop.
Save askz/91fc3368691501ff0f4d2d838ec6b4f5 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/* user@192.168.171.100:/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 root@192.168.171.100 "tar czvpf - /home" | tar xzpf - -C /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment