kazmax - Home Server on Linux

Change Linux group information - groupmod

You can change group information with the groupmod command. The groupmod command can change group name and GID.

Last Update : December 25, 2018

Change Linux group information - groupmod Contents

  1. Usage and options of "groupmod" command
  2. Changing the group name and GID with the groupmod command.
  3. Files that the "groupmod" command changes.

1. Usage and options of "groupmod" command

Usage

groupmod [ -g gid [-o ] ] [ -n new_group_name  ] group_name

group_name is the name of the group to be changed

OPTIONS

OPTIONS Description
-g Change the GID of group_name to gid specified
-n Changing the group name of the specified group_name to new_group_name.
-o allow to change the group GID to a non-unique value.

2. Changing the group name and GID with the groupmod command.

To change the group name with the groupmod command, use the command as follows.

[root@localhost ~]# tail -1 /etc/group
before_group:x:515:
↑ before_group group exists

[root@localhost ~]# groupmod -n after_group before_group ← Change group name
[root@localhost ~]# tail -1 /etc/group
after_group:x:515:
↑ Changed to after_group group

To change the GID with the groupmod command, do the following.

[root@localhost ~]# tail -1 /etc/group
after_group:x:515:
↑ GID is 515

[root@localhost ~]# groupmod -g 520 after_group ← Change GID to 520
[root@localhost ~]# tail -1 /etc/group
after_group:x:520:
↑ GID changed to 520

Notes

Notes on changing GID

Changing the GID of a group does not change the group set in the existing file or directory.

[root@localhost tmp]# tail -1 /etc/group
after_group:x:515:
↑ The GID of after_group is 515

[root@localhost tmp]# ls -l
-rw-r--r--  1 hoge1 after_group 0 Oct 27 03:57 test.txt
↑ The "after_group" group is set in the file

[root@localhost tmp]# groupmod -g 520 after_group← Change the GID of "after_group" group to 520

[root@localhost tmp]# ls -l
-rw-r--r--  1 hoge1 515 0 Oct 27 03:57 test.txt
↑ Groups of files are not changed. The old GID of the group will be displayed.

To change the group of files and directories at once, you can do as follows.

[root@localhost ~]# find / -gid 515 -exec chgrp after_group {} \;

I am executing "chgrp" command (command to change group ownership of file) for GID 515 files and directories.

3. Files that the "groupmod" command changes.

The files that the groupmod command changes are the following two files.

  • /etc/group
  • /etc/gshadow

Like the groupadd command, the system recognizes group changes even if you modify these files directly without using commands.