linux groupmems命令

Because users group membership is defined in two different locations, it can be difficult to find out which groups exactly a user is a member of. A convenient command to check this is  groupmems . Use, for example, the command  groupmems -g sales -l  to see which users are a member of the group sales. This shows users who are a member of this group as a secondary group assignment, but also users who are a member of this group as the primary group assignment. 

[root@rhel7 ~]# groupmems --help
Usage: groupmems [options] [action]

Options:
  -g, --group groupname         change groupname instead of the user's group
                                (root only)
  -R, --root CHROOT_DIR         directory to chroot into

Actions:
  -a, --add username            add username to the members of the group
  -d, --delete username         remove username from the members of the group
  -h, --help                    display this help message and exit
  -p, --purge                   purge all members from the group
  -l, --list                    list the members of the group

例:

查看有哪些用户属于sales组

[root@rhel7 ~]# groupmems -g sales -l
linda lisa

从sales组中删除lisa

[root@rhel7 ~]# groupmems -d lisa -g sales  
[root@rhel7 ~]# groupmems -g sales -l
linda 

添加用户到组里

[root@rhel7 ~]# id lxj2
uid=1002(lxj2) gid=0(root) groups=0(root)
[root@rhel7 ~]# groupmems -a lxj2 -g sales
[root@rhel7 ~]# id lxj2
uid=1002(lxj2) gid=0(root) groups=0(root),1238(sales)

也可以使用usermod命令将用户添加到组里 

usermod -aG  will add users to new groups that will 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 -aG sales linda  
usermod -aG sales lisa  
usermod -aG account lori  
usermod -aG account bob 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值