Because Users group membership is defined in the different locations, it can be difficult to find out which groups exactly A user is a member of. A Convenient command to check that is groupmems . Use, for example, the command groupmems-g sales-l to see which users is a member of the group sales. This shows users who is a member of this group as a secondary group assignment, but also the users who is a member of this G Roup as the primary group assignment.
[Email protected] ~]# Groupmems--helpusage:groupmems [Options] [action]options:-G,--group groupname change groupname instead of the user'S Group(Root only)-R,--root Chroot_dir directory to CHROOT intoactions:-A,--Add username add username to the members of the group-D,--delete username remove username fromThe members of the group-H,--help display ThisHelp message and exit-P,--purge purge all members fromThe group-L,--list list the members of the group
Cases:
See which users belong to the sales group
[Email protected] ~]# groupmems-g sales-Llinda Lisa
Remove Lisa from the sales group
[Email protected] ~]# groupmems-d lisa-G sales ~]# groupmems-g Sales-
Add user to Group
[[Email protected] ~]# ID lxj2uid=1002(lxj2) gid=0(root) groups=0~]# Groupmems-a lxj2-~]# id lxj2uid=1002(lxj2) gid=0(root) groups=0(Root), 1238 (sales)
You can also use the Usermod command to add users to a group
Usermod-ag would add users to new groups that would be used as their secondary group.
Use Usermod to add users Linda and Lisa to the group sales, and Lori and Bob to the group account:
Usermod-AGSales Linda -AGsales Lisa -AG account Lori
Linux Groupmems commands