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
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3323 times since Tue, Aug 6, 2019
Set Up SSH Tunneling on a Linux / Unix / BSD Server To Bypass NAT
Viewed 11387 times since Fri, May 15, 2020
logrotate Understanding logrotate utility
Viewed 1880 times since Sun, Jan 12, 2020
20 Linux Command Tips and Tricks That Will Save You A Lot of Time linux
Viewed 4840 times since Thu, Apr 18, 2019
RHEL: Display swap/RAM size
Viewed 3389 times since Sat, Jun 2, 2018
OpenSSL: Check SSL Certificate Expiration Date and More
Viewed 6915 times since Mon, Feb 18, 2019
Linux - How to unlock and reset user’s account
Viewed 4661 times since Fri, Jun 8, 2018
Sample logrotate configuration and troubleshooting part 2
Viewed 9578 times since Fri, Nov 30, 2018
Fedora 32: Simple Local File-Sharing with Samba CIFS Linux
Viewed 8913 times since Sun, Dec 6, 2020
chrt command: Set / Manipulate Real Time Attributes of a Linux Process
Viewed 11178 times since Mon, Feb 17, 2020