How to Change the UID or GID for a User or Group
August 27, 2023 —
Gregg Szumowski
Let’s assume we have a user, Jane Doe, with the username of jdoe and the UID of 1001 who we need to move to another UID (for some reason or another).
First, change the UID of the user:
# usermod -u 3001 jdoe
Next, use search and change all file’s ownership owned by this user:
# find / -user 1001 -exec chown -h jdoe {} \;
What if we need to change the GID of a group? Basically the same process can be used. Let’s say we want to change the admins group’s GID from 2001 to 4001.
First, change the GID:
# groupmod -g 4001 admins
Now, use search and change all file’s ownership owned by this group:
# find / -group 2001 -exec chgrp -h admins {} \;