用戶組的創建:
1 |
groupadd [OPTION] 組名 |
用戶組的修改
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)