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

Solved issue
Joined
Apr 16, 2023
Messages
149
Reaction score
16
Credits
1,460
I'm on centos 7. I'm wondering what could be the differences between these two?
I've read this but could not grasp what they're trying to say. Can you give me an example scenario to work with?
 


The -a stands for append, if you only use -G it will remove all the other supplementary groups that the user was a member of before.
Code:
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
[root@localhost ~]# usermod -G group1 testuser
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(group1)
[root@localhost ~]# usermod -G group2 testuser
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1003(group2)
[root@localhost ~]# usermod -aG group1 testuser
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(group1),1003(group2)
 
The -a stands for append, if you only use -G it will remove all the other supplementary groups that the user was a member of before.
Code:
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
[root@localhost ~]# usermod -G group1 testuser
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(group1)
[root@localhost ~]# usermod -G group2 testuser
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1003(group2)
[root@localhost ~]# usermod -aG group1 testuser
[root@localhost ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(group1),1003(group2)
Thanks for the crisp example. I think I've got it.
 

Members online


Top