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

Click For Summary
SUMMARY

The discussion clarifies the differences between the "usermod -aG" and "usermod -G" commands in CentOS 7. The "usermod -aG" command appends a user to specified secondary groups without removing existing group memberships, while "usermod -G" replaces all secondary group memberships with the specified groups. For example, using "usermod -aG project-a pbuk" adds the user 'pbuk' to the 'project-a' group, whereas "usermod -G project-c pbuk" removes all previous secondary groups and assigns 'pbuk' only to 'project-c'.

PREREQUISITES
  • Understanding of Linux user and group management
  • Familiarity with command-line interface in CentOS 7
  • Basic knowledge of user permissions and group roles
  • Experience with the 'id' command for checking user group memberships
NEXT STEPS
  • Research the 'usermod' command options in Linux
  • Learn about user and group permissions in CentOS 7
  • Explore the implications of group management on user access control
  • Study best practices for managing user accounts in Linux environments
USEFUL FOR

System administrators, Linux users managing group permissions, and anyone involved in user account management on CentOS 7.

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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 10 ·
Replies
10
Views
1K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 21 ·
Replies
21
Views
2K
Replies
2
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K