-   Linux - Security (
-   -   Chang GID numbers (

sdefor 03-18-2007 10:13 AM

Chang GID numbers
Im looking to change GID numbers for certian groups.
My initial thought is to open /etc/group and change the number to what it needs to be. My concern might be for files that were created under the old group ID. Similar to changing a UID. Any thoughts on this?

The reason I am doing this, is because I am trying to make several servers that have the same UID's and GID's (same group names and user names).

But something tells me just editing /etc/group will do fine. The UID's however would be a little more involved (finding all files and modifiying them).


jschiwal 03-18-2007 10:27 AM

You could use the -gid argument of the find command to locate files owned by a group. You can also use -exec to run the chgrp command on that file.

sdefor 03-18-2007 10:52 AM

Thanks for the reply!

So I could in effect do the following...
login as 'root'

For UID change use the command....

$usermod -u <newUID> <username> ## or modify /etc/passwd

Then to find files to modify to new UID use the command...

$find / -user <oldUID> -print -exec chown <newUID> {}\;

And for GID
modify /etc/group

Then to find files to modify to NEW GID if any use...

$find / -gid <oldGID> -print -exec chgrp <newGID> {}\;

Would the above look appropriate?


jschiwal 03-18-2007 05:20 PM

I wouldn't recommend starting at the root directory. You will waste a lot of time doing it that way. Searching for group owned files in /proc, /sys, /mnt or /dev isn't what you want to do. Excluding certain directories can make the command too complicated.

You could use a form like:
find /home /tmp /var /usr ...
instead to apply it on directories that you know have the group's files.

Also, use su or sudo instead, and log in as a normal user. It is a good habit to get into. (And enforced if you have Ubuntu)

sdefor 03-18-2007 07:07 PM

That's an excellent point, and some great advice. I will give it a shot on a few bogus users as well as groups and files. I forget sometimes that being logged in as root is not always the "wise" thing to do.

Thanks Again

All times are GMT -5. The time now is 01:30 AM.