https://kerneltalks.com/tips-tricks/how-to-change-uid-or-gid-safely-in-linux
In this article, we will walk you through to change UID or GID of existing user or group without affecting file ownership owned by them. Later, we also explained how to switch GID between two groups and how to switch UID between two users on the system without affecting file ownership owned by them.
Let’s start with changing UID or GID on the system.
Group sysadmin with GID 2001
Group sysadmin with GID 4001
Changing GID and UID is simple using usermod or groupmod command, but you have to keep in mind that after changing UID or GID you need to change ownership of all files owned by them manually since file ownership is known to the kernel by GID and UID, not by username.
The procedure will be –
Change UID or GID as below :
Now, search and change all file’s ownership owned by this user or group with
for loop
That’s it. You have safely changed UID and GID on your system without affecting any file ownership owned by them!
Group oracle with GID 2222
Group oracle with GID 1111
In above situation, we need to use one intermediate GID which is currently not in use on your system. Check /etc/group file and select one GID XXXX which is not present in a file. In our example, we take 9999 as intermediate GID.
Now, the process is simple –
Learn how to change UID or GID safely
in Linux. Also, know how to switch UID between two users and GID
between two groups without impacting files ownership they own.
In this article, we will walk you through to change UID or GID of existing user or group without affecting file ownership owned by them. Later, we also explained how to switch GID between two groups and how to switch UID between two users on the system without affecting file ownership owned by them.
Let’s start with changing UID or GID on the system.
Current scenario :
User shrikant with UID 1001Group sysadmin with GID 2001
Expected scenario :
User shrikant with UID 3001Group sysadmin with GID 4001
Changing GID and UID is simple using usermod or groupmod command, but you have to keep in mind that after changing UID or GID you need to change ownership of all files owned by them manually since file ownership is known to the kernel by GID and UID, not by username.
The procedure will be –
Change UID or GID as below :
How to switch GID of two groups
Current scenario :
Group sysadmin with GID 1111Group oracle with GID 2222
Expected scenario :
Group sysadmin with GID 2222Group oracle with GID 1111
In above situation, we need to use one intermediate GID which is currently not in use on your system. Check /etc/group file and select one GID XXXX which is not present in a file. In our example, we take 9999 as intermediate GID.
Now, the process is simple –
- Change sysadmin GID to 9999
- Find and change group of all files owned by GID 1111 to sysadmin
- Change oracle GID to 1111
- Find and change group of all files owned by GID 2222 to oracle
- Change sysadmin GID to 2222
- Find and change group of all files owned by GID 9999 to sysadmin
No comments:
Post a Comment