linux 用戶遷移
一: 目的.
現有服務器用戶,完整遷移到一臺新服務器.
二: 環境:
源: 117
cat /etc/redhat-release
CentOS release 6.9 (Final)
rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
目的114
cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
三:
117:
export UGIDLIMIT=500 //設置一個變量, 新建的uid 從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
rsync -e ssh -avpr /root/move/ [email protected]
rsync -e ssh -avpr /home [email protected]:/ //把舊服務器上的home整個目錄,copy到新服務器上.
本例不考慮/var/spool/mail
四: 114:
30 cat passwd.mig >> /etc/passwd
31 cat group.mig >> /etc/group
33 cat shadow.mig >> /etc/shadow
34 cp gshadow.mig /etc/gshadow
[[email protected]