Skip to content

Instantly share code, notes, and snippets.

@deviousway
Last active October 1, 2018 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deviousway/e4100a67882d5dbbfbe6ea5d65ef644e to your computer and use it in GitHub Desktop.
Save deviousway/e4100a67882d5dbbfbe6ea5d65ef644e to your computer and use it in GitHub Desktop.
linux copy/migrate users from one server to another
mkdir move/
export UGIDLIMIT=500
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig
cp /etc/gshadow /root/move/gshadow.mig
scp -r /root/move/* user@new.linuxserver.com:/path/to/location
mkdir /root/newsusers.bak
cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak
cat passwd.mig >> /etc/passwd
cat group.mig >> /etc/group
cat shadow.mig >> /etc/shadow
cp gshadow.mig /etc/gshadow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment