Move RHEL Users
Step 1, on source
Run the following commands as root source) system which has users configured
ID_minimum=500
for f in /etc/{passwd,group}; do awk -F: -vID=$ID_minimum '$3>=ID && $1!="nfsnobody"' $f |sort -nt: -k3 > ${f#/etc/}.bak; done
while read line; do grep -w "^${line%%:*}" /etc/shadow; done <passwd.bak >shadow.bak
while read line; do grep -w "^${line%%:*}" /etc/gshadow; done <group.bak >gshadow.bak
After running the above, 4 new files will be in the current directory (passwd.bak, group.bak, shadow.bak, and gshadow.bak). Inspect them and then transfer to the new destination system.
Step 2, on destination
Run the following command as root on the destination system in a directory containing the four .bak files.
for f in {passwd,group,shadow,gshadow}.bak; do cat $f >>/etc/${f%.bak}; done
Step 3, on destination
Run the following final compound command destination system in the same directory as the previous step
for uidgid in $(cut -d: -f3,4 passwd.bak); do
dir=$(awk -F: /$uidgid/{print\$6} passwd.bak)
mkdir -vm700 "$dir"; cp -r /etc/skel/.[[:alpha:]]* "$dir"
chown -R $uidgid "$dir"; ls -ld "$dir"
done
This final command will setup home directories for the users.
No Comments