groups和groups username id同理
新增一个用户到用户组后,groups和groups username显示结果不同,重启后才生效
找到的两个回答如下:
Because changes to group membership only take effect after starting a new login shell. Starting a new non-login interactive shell session (which is what you get when you open a new terminal) is irrelevant.
So, when you run groups
, that prints the groups your user is currently in. However, those were set up when your user first logged in and cannot be changed until you log in again. Therefore, groups
doesn't include your new group.
On the other hand, when you run groups myuser
, the system doesn't look for the groups the current user belongs to at the moment, it looks up the groups that the user myuser
belongs to, which it gets by reading the settings file (/etc/group
, presumably). Since your user is set up to belong to the new group in /etc/groups
, this command shows that as well, even though you're not currently in that group since you haven't logged in again.
-
When you run
groups
without an argument, it shows the groups list of the current process. Normally, the list is simply inherited from the parent process, but it is changed bylogin
,newgrp
and similar. -
When you run
groups
with an argument, it shows the groups that are listed (in the user databases) for the specified user. That's the group list thatlogin
etc. will set the next time it's run for that user.
This is why updating the user/group databases will only affect future login sessions - don't expect it to change any processes that are already running.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2017-12-25 CentOS针对磁盘IO[jdb2进程]的优化