/**/ How to use groupmod command in linux? - Dextutor

How to use groupmod command in linux?

Use

groupmod command in linux is used to modify the information related to any existing group.

Syntax

groupmod [options] GROUP

Options used with groupmod command in linux.

1. Change the GID of the group

-g : option changes the group ID of the group. But, the value specified must be unique and non-negative.

For Example: An existing group in the system G1 has the group ID 983.

Before -g option with groupmod command in linux
Before -g option with groupmod

Next, We use -g option with groupdel to change the group ID of G1 from 983 to 9000.

-g option with groupdel command in linux
-g option with groupmod
2. Change the group name

-n : option changes the group name to a new one.

For Example: There exists group G1 having GID 9000 as highlighted in figure below.

Before -n option with groupmod
Before -n option with groupmod

Now, we change the name from G1 to Group1 (the GID remains the same).

-n option with groupmod
3. To have non-unique GID

-o : option allows having non unique GIDs. Remember, this option can be used along with -g option only.

For Example: There are two groups in my system – Group1(having GID 9000) and Group2(having GID 9001).

Before -g option with groupmod
Before -o option with groupmod

Next, we change the GID of Group2 to 9000. After this change both Group1 and Group2 will have the same GID i.e., 9000.

-o option with groupmod
-o option with groupmod
4. Set password

-p : options sets the password. But, this option is not recommended as the password will be visible to users.

Files related to groupmod command in linux

/etc/group – contains the information about the groups in the system. Thus, you can view the contents of this file to check whether a group is there in the system or not.

/etc/gshadow – contains the secure information about the groups in the system

/etc/login.defs – Shadow password suite configuration file

/etc/passwd – contains information about user account. Thus, you can view the contents of this file to check whether a user is there in the system or not.

Related commands

Some useful questions

Q1. What is/are the benefit(s) of having same GID with -o option for multiple groups?

Q2. If the group ID of any group is changed with -g option then what happens to the files belonging to that group?

Leave a Comment