Created
March 27, 2018 19:02
-
-
Save reikoNeko/9b1e47117f56278027425e69cc0dafbb to your computer and use it in GitHub Desktop.
Renumber a batch of users' uids and gids, and fix file ownerships
This file contains hidden or 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
#!/bin/bash | |
while IFS="," read -r name olduid oldgid newuid newgid | |
do | |
/usr/sbin/groupmod $name -g $newgid | |
/usr/sbin/usermod $name -u $newuid -g $newgid | |
/bin/chown --changes --silent --no-dereference --recursive \ | |
--from=:$oldgid :$name /home/$name | |
done << END | |
tinker,8001,8001,701,701 | |
evans,8002,8005,702,702 | |
chance,8003,8006,703,703 | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works in Centos 6, where usermod automatically changes file permissions but groupmod does not. YMMV