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

Click For Summary
The discussion clarifies the difference between the "usermod -aG" and "usermod -G" commands in Linux. The "usermod -aG" option appends a user to additional groups without removing existing ones, while "usermod -G" replaces all secondary groups with the specified group. An example illustrates that using "usermod -aG project-a" adds the user to the project-a group, while "usermod -G project-c" deletes all other secondary groups and only adds project-c. This distinction is crucial for managing user permissions effectively. Understanding these commands helps prevent unintended group removals in Linux user management.
Technology news on Phys.org
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)
 
thanks for the example.