Forked from lovellfelix/gist:9b7181b218ab02b4314e7ccd0194bbe2
Created
April 11, 2017 10:01
-
-
Save askz/91fc3368691501ff0f4d2d838ec6b4f5 to your computer and use it in GitHub Desktop.
Migrate Linux users to another server
This file contains 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 / | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment