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
Linux nslookup Command Examples for DNS Lookup
Viewed 10315 times since Sat, Sep 29, 2018
OpenSSL: Check If Private Key Matches SSL Certificate & CSR
Viewed 4248 times since Mon, Feb 18, 2019
Linux Customizing Bash
Viewed 3177 times since Sun, Dec 6, 2020
stunnel How To Encrypt Traffic to Redis with Stunnel on Ubuntu 16.04
Viewed 3205 times since Sun, Dec 6, 2020
Setup SSL Tunnel Using Stunnel on Ubuntu
Viewed 4123 times since Fri, Sep 28, 2018
LVM: Move allocated PE between Physical Volumes
Viewed 5175 times since Sat, Jun 2, 2018
Oracle Linux 7 – How to audit changes to a trusted file such as /etc/passwd or /etc/shadow
Viewed 4048 times since Wed, Jul 25, 2018
ZPOOL: Add a mirror to a concat zpool
Viewed 4872 times since Sun, Jun 3, 2018
RHCS6: Reduce a Global Filesystem 2 (GFS2)
Viewed 4323 times since Sun, Jun 3, 2018
LVM: Remove an existing Volume Group
Viewed 6506 times since Sat, Jun 2, 2018