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 {} \;
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
LVM: Create a new Logical Volume / Filesystem
Viewed 2195 times since Sat, Jun 2, 2018
RHEL: Remove existing SAN LUNs
Viewed 14243 times since Sat, Jun 2, 2018
Understanding logrotate utility part 1
Viewed 1886 times since Fri, Nov 30, 2018
LUKS List available methods of encryption for LUKS
Viewed 3085 times since Fri, Jul 13, 2018
stunnel Securing telnet connections with stunnel
Viewed 1640 times since Sun, Dec 6, 2020
VMWare tools free
Viewed 9199 times since Mon, Jul 16, 2018
Linux: Disks diagnostic using smartctl
Viewed 15281 times since Wed, Jul 25, 2018
HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples
Viewed 5512 times since Fri, Nov 30, 2018
How to recover error - Audit error: dispatch err (pipe full) event lost
Viewed 26238 times since Tue, Aug 6, 2019
Linux Chage Command to Set Password Aging for User
Viewed 2572 times since Tue, Sep 11, 2018