Change gid of a specific group

  • I'd like to change group id of a specific group. There are so may solution for changing the gid of a file or directories. But that's not what I want. Is there a way to do that?

  • The GID is the primary identifier of the group. As far as the system is concerned, a different GID is a different group. So to change the GID, you're going to have to modify all the places where that GID is used.

    You should avoid treating the GID as significant and use group names instead; you can change the name of a group with a single command (on Linux: groupmod -n NEW_GROUP_NAME OLD_GROUP_NAME).

    However, if you do really want to change the GID, this is how:

    • First, you may need to log out users in the group and kill processes who have that group as their effective, real or saved group.
    • Change the entry in the group database. On Linux, run groupmod -g NEWGID GROUPNAME. On other systems, use that system's administration tool, or vigr if available, or edit /etc/group as applicable.
    • Change the group of all the files on your system that belong to the old group.

      find / -gid OLDGID ! -type l -exec chgrp NEWGID {} \;
    • chgrp clears suid and sgid flags, restore those.

    • If you have any archive that uses the old GID, rebuild it.
    • If you have any configuration file or script that references the old GID, update it.
    • Restart all processes that must use the new GID.

    Suggest using `chgrp -h ...` instead of `chgrp ...`. Without `-h`, the *target* of any relevant symlink will have its group changed.

    `groupmod` take's a name as the main argument for me... `groupmod -g NEWGID GROUPNAME`

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM