博客园  :: 首页  :: 管理

每天一个Linux命令-用户管理-gpasswd

Posted on 2020-06-06 21:49  520_1351  阅读(647)  评论(0编辑  收藏  举报

gpasswd命令是一个用户/用户组管理的命令,常用的实例如下:

 

1、为webgroup组用户设置密码:gpasswd  webgroup

      用户组密码,可以在一个用户想要临时切换自己的主属组为webgroup时,可以用到

      这个用户可以与webgroup组没有任何关系,都是可以使用newgrp webgroup临时切换的(必须得有密码)

      切换成功后,使用id可以看到自己的主属组就是webgroup,创建的文件的所属组也是webgroup

      无论webgroup是否设置了密码,如果是webgroup组的成员切换是不需要密码的!

       

2、将user01用户加入到webgroup组(要从wheel组中删除,在下命令将-a替换成-d选项即可)

      gpasswd -a user01 webgroup           //这样user01也就是webgroup用户组的一个成员了,不会改变user01的主属组

      另外:如果有其他用户的主属组是webgroup,那么-d是无法删除的,因为未被视为webgroup组的member(成员)

3、移除webgroup用户组的组密码(其实就是将组的密码位置空)

      gpasswd -r  webgroup                       //默认新建一个组,/etc/gshadow的密码位是!,无论是!还是密文,都会被清空

 

4、指定一个或者多个用户作为webgroup组的成员,多个用户名之间只能以逗号隔开

       gpasswd -M user02,user03,user04 webgroup   //注意:无论之前webgroup组成员有多少,这条命令执行后,就这3个成员了

5、指定一个或者多个用户作为webgroup组的管理员(不一定得是webgroup组的成员)

       gpasswd -A user00,user01 webgroup     //可以通过/etc/gshadow的第三列看出效果,管理员可以增删成员,修改组密码等操作

[root@5201351 ~]# cat /etc/group |grep webgroup
webgroup:x:1003:user02,user03,user04
[root@5201351 ~]# cat /etc/gshadow |grep webgroup
webgroup:!:user00,user01:user02,user03,user04

 6、限制其他用户访问到组(即登录到组),只有组中的成员才可以用newgrp临时切换该组,作为自己的主属组

       gpasswd -R  webgroup               //执行后/etc/gshadow中的密码位就会被重置为一个感叹号!

 

关于gpasswd命令的使用帮助如下:

[root@5201351 ~]# gpasswd --help
Usage: gpasswd [option] GROUP

Options:
  -a, --add USER                add USER to GROUP
  -d, --delete USER             remove USER from GROUP
  -h, --help                    display this help message and exit
  -Q, --root CHROOT_DIR         directory to chroot into
  -r, --delete-password         remove the GROUP's password
  -R, --restrict                restrict access to GROUP to its members
  -M, --members USER,...        set the list of members of GROUP
  -A, --administrators ADMIN,...
                                set the list of administrators for GROUP
Except for the -A and -M options, the options cannot be combined.

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/13056641.html