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 |
This works in Centos 6, where usermod automatically changes file permissions but groupmod does not. YMMV
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not for random fun (at least not on a production machine). This is for when you need to put a legacy machine onto LDAP, AD, or another system that has been assigned a block of UIDs/GIDs and you have existing users and groups in that range. Do research to futureproof your decisions, and then it helps to make a spreadsheet and export the values as CSV to be added into the data section.