RHEL: How to change a USER/GROUP UID/GID and all owned files


RHEL: How to change a USER/GROUP UID/GID and all owned files

# How to change a UID/GID and all belonging files

USER=myuser
OLDUID=7773
NEWUID=7774
GROUP=mygroup
OLDGID=157
NEWGID=158



# Assign a new UID to USER. Any files which the user owns and which are located in the
# directory tree rooted at the user's home directory will have the file user ID changed
# automatically. Files outside of the user's home directory must be altered manually.

usermod -u $NEWUID $USER

# Assign a new GID to GROUP. Any files which the old group ID is the file group ID must
# have the file group ID changed manually.

groupmod -g $NEWGID $GROUP


# Manually change files with old UID

find / -user $OLDUID -exec chown -h $USER {} \;


# Manually change files with old GID

find / -group $OLDGID -exec chgrp -h $GROUP {} \;


Article Number: 143
Posted: Sat, Jun 2, 2018 9:12 AM
Last Updated: Sat, Jun 2, 2018 9:12 AM

Online URL: http://kb.ictbanking.net/article.php?id=143