Linux 组管理

  • [x] CentOS Linux release 7.6.1810 (Core)

查看所有用户组

shell > getent group

创建用户并分配到指定的组

shell > useradd -G sudo test002 

添加组

shell > groupadd test001
shell > groupadd test002

更改用户的主要组

主要组的作用主要体现在用户创建文件或文件夹的时候, 默认分配的所属组

# 添加test用户到test001组
shell > usermod -g test001 test

更改用户的次要组

# 添加test用户到test001组
shell > usermod -a -G test001 test
shell > usermod -a -G test001,test002 test

# 添加test用户到sudo组
shell > usermod -a -G sudo test

查看用户所属组

#查看当前用户所属组
shell > groups
shell > id

#查看指定用户所属组
shell > groups test
shell > id test