Skip to content

Instantly share code, notes, and snippets.

@reikoNeko
Created March 27, 2018 19:02
Show Gist options
  • Save reikoNeko/9b1e47117f56278027425e69cc0dafbb to your computer and use it in GitHub Desktop.
Save reikoNeko/9b1e47117f56278027425e69cc0dafbb to your computer and use it in GitHub Desktop.
Renumber a batch of users' uids and gids, and fix file ownerships
#!/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
@reikoNeko
Copy link
Author

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