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
Use inotify-tools on CentOS 7 or RHEL 7 to watch files and directories for events
Viewed 14086 times since Fri, Jul 27, 2018
What is OS Watcher Utility and How to use it for Database Troubleshooting ?
Viewed 30206 times since Thu, Jun 21, 2018
“Too many authentication failures” with SSH
Viewed 6072 times since Mon, May 21, 2018
RHEL: Route network packets to go out via the same interface they came in
Viewed 3118 times since Sat, Jun 2, 2018
Using stunnel and TinyProxy to obfuscate HTTP traffic
Viewed 6966 times since Fri, Sep 28, 2018
awk printf
Viewed 15203 times since Wed, Aug 19, 2020
LVM: Rename root VG/LV
Viewed 7651 times since Sat, Jun 2, 2018
A Simple Guide to Oracle Cluster File System (OCFS2) using iSCSI on Oracle Cloud Infrastructure
Viewed 8436 times since Sat, Jun 2, 2018
SSH: Execute Remote Command or Script – Linux
Viewed 2437 times since Mon, Feb 18, 2019
Using renice and taskset to manage process priority and CPU affinity with Linux OEL 6.4
Viewed 3646 times since Mon, Feb 17, 2020