Difference between "usermod -aG" and "usermod -G" options in linux?

In summary, the conversation discusses the differences between the "usermod -aG" and "usermod -G" options on CentOS 7, with the former adding a user to a secondary group and the latter replacing all secondary groups with a new one. An example scenario is provided to demonstrate the effects of each option.
Technology news on Phys.org
  • #2
Code:
$ id pbuk
uid=1001(pbuk) gid=1002(pbuk) groups=1002(pbuk)
$ # Adds project-a as a secondary group
$ usermod -aG project-a pbuk
$ id pbuk
uid=1001(pbuk) gid=1002(pbuk) groups=1002(pbuk),1003(project-a)
$ # Adds project-b as a secondary group
$ usermod -aG project-b pbuk
$ id pbuk
uid=1001(pbuk) gid=1002(pbuk) groups=1002(pbuk),1003(project-a),1004(project-b)
$ # Deletes all secondary groups then adds project-c as a secondary group
$ # (this is not often what you want to do)
$ usermod -G project-c pbuk
$ id pbuk
uid=1001(pbuk) gid=1002(pbuk) groups=1002(pbuk),1005(project-c)
 
  • #3
thanks for the example.
 

1. What is the difference between the "usermod -aG" and "usermod -G" options in Linux?

The "usermod -aG" option is used to add a user to supplementary groups without removing them from any existing groups. The "usermod -G" option replaces the user's current supplementary groups with the specified groups.

2. Can I use both the "usermod -aG" and "usermod -G" options together?

Yes, you can use both options together to add a user to a new supplementary group without removing them from any existing groups, and at the same time, replace their current supplementary groups with the specified groups.

3. What happens if I use the "usermod -G" option without specifying any groups?

If you do not specify any groups with the "usermod -G" option, then the user will be removed from all supplementary groups except for the primary group.

4. Can I use the "usermod -aG" option to remove a user from a specific group?

No, the "usermod -aG" option is only used to add a user to supplementary groups. To remove a user from a specific group, you can use the "usermod -G" option with the group name prefixed by a minus sign, e.g. "usermod -G -groupname username".

5. Are there any other options for managing user groups in Linux?

Yes, there are other options such as "groupadd" for creating new groups, "groupdel" for deleting groups, and "gpasswd" for managing group passwords. These tools provide more advanced options for managing user groups in Linux.

Similar threads

  • Computing and Technology
Replies
24
Views
3K
  • Computing and Technology
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
632
  • Computing and Technology
Replies
18
Views
1K
Replies
2
Views
1K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
5K
  • Programming and Computer Science
Replies
21
Views
1K
Replies
10
Views
2K
  • Programming and Computer Science
Replies
19
Views
1K
Back
Top