Linux用户组的添加及属性的更改

用户组的创建:

1
2
3
4
5
groupadd [OPTION]  组名
-g GID 指明GID号;[GID_MIN, GID_MAX]
-r 创建系统组
CentOS 6: ID<500
CentOS 7: ID<1000

用户组的修改

groupmod [OPTION]  组名
    -n group_name: 新名字
    -g GID: 新的GID

用户组的删除

groupdel 组名

更改和查看组成员:

groupmems [options] [action]
    options:
        -g, --group groupname 更改为指定组 (只有root)
    actions:
        -a, --add username 指定用户加入组
        -d, --delete username 从组中删除用户
        -p, --purge 从组中清除所有成员
        -l, --list 显示组成员列表

首先通过groupadd 组名创建一个新组。并通过groupmems -a 用户名 -g 组名添加一个用户到某个组中。

1
2
3
4
5
6
7
8
大专栏  Linux用户组的添加及属性的更改ass="line">9
[root@localhost ~]# groupadd test
[root@localhost ~]# getent group test
test:x:1008:
[root@localhost ~]# groupmems -a tom -g test
[root@localhost ~]# groupmems -a jim -g test
[root@localhost ~]# groupmems -a user1 -g test
[root@localhost ~]# groupmems -a user2 -g test
[root@localhost ~]# getent group test
test:x:1008:tom,jack,jim,user1,user2

添加删除用户到组中的另一种方法。

1
2
3
4
[root@localhost ~]# gpasswd -a tom jim
Adding user tom to group jim
[root@localhost ~]# gpasswd -d tom test
Removing user tom from group test

通过groupmems -l -g 组名,列出该组的成员。

[root@localhost ~]# groupmems -l -g test
    tom  jack  jim  user1  user2 

groups [OPTION].[USERNAME] 查看用户所属组列表

[root@localhost ~]# groups tom
tom : tom jim
[root@localhost ~]# id tom
uid=1000(tom) gid=1000(tom) groups=1000(tom),1001(jim)
原文地址:https://www.cnblogs.com/lijianming180/p/12251450.html