用 groups 查看用户所属的组
查清用户的 sudo、docker 或文件权限来自哪些组——“权限不够”时的第一诊断命令。
执行 `groups alice`(省略用户名则查自己),列出该账户所属的全部组。
01命令
命令
$ groups alice02作用说明
Linux 上大部分文件和能力访问都是通过组授予的——wheel/sudo 给 root 权限,docker 给守护进程套接字,www-data 给网站目录。`groups 用户名` 通过 NSS 解析组成员关系,域用户同样适用。两个坑:用 usermod 新加的组只对之后的登录会话生效,需要 `newgrp docker` 或重新登录;另外 `getent group docker` 显示的成员列表不含以它为主组的用户。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- groups(1) — print group memberships a user is in依据: Documents groups printing the group names for a specified user, defaulting to the current user.
最后验证: 2026-09-17 · 分类: 安全与隐私