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 Multiple SSH Command On Remote Machine And Exit Safely
Viewed 4110 times since Tue, Aug 6, 2019
How to do a Filesystem Resize (ext3/ext4) on Redhat running on VMware
Viewed 10881 times since Wed, Jul 25, 2018
RHEL: Manually encrypting a filesystem with LUKS
Viewed 3625 times since Sun, May 27, 2018
debian How to check Debian CVE status using python script
Viewed 3437 times since Sun, Sep 23, 2018
Linux Screen
Viewed 1922 times since Sat, Jun 2, 2018
10 Linux DIG Command Examples for DNS Lookup
Viewed 10914 times since Sun, Sep 30, 2018
A Simple Guide to Oracle Cluster File System (OCFS2) using iSCSI on Oracle Cloud Infrastructure
Viewed 8078 times since Sat, Jun 2, 2018
how to list all hard disks in linux from command line
Viewed 3257 times since Mon, Jan 28, 2019
ZFS: Verify/change properties of a zfs filesystem
Viewed 2447 times since Sun, Jun 3, 2018
How to configure an SSH proxy server with Squid
Viewed 2912 times since Sun, Dec 6, 2020