Bra*_*ley 7 linux command-line coreutils audit uid
我想看看是否id -r会打印出登录系统的用户的 UID 或用户名,尽管有任何su's 或sudo's 。我对这样做很感兴趣,所以我可以让人们更加负责并相应地定制脚本功能(即:他们在脚本上发出 sudo 并从登录用户的主目录中提取信息)。
我实现了sudo集合,SUDO_USER但我不想依赖它,因为它是一个可由用户修改的变量,并且它只有发出最近 sudo 的用户的用户名(即:sudo -i ; sudo -iu randomUser ; echo $SUDO_USER打印出“root”而不是实际用户)。
手册页中的任何内容或我可以在网上找到的内容似乎都表明此命令的正确用法是什么,并且明显的排列不起作用:
[root@ditirlns03 ~]# id -r
id: cannot print only names or real IDs in default format
[root@ditirlns03 ~]# id -r jadavis6
id: cannot print only names or real IDs in default format
[root@ditirlns03 ~]# id -r root
id: cannot print only names or real IDs in default format
Run Code Online (Sandbox Code Playgroud)
在这一点上,我仍然不确定id -r是否要打印出我想要的东西,主要是因为我根本不知道如何让它打印出任何东西。
-r必须与另一个选项结合使用。例如:
$ id -Gr
1000 4 24 27 30 46 109 124
Run Code Online (Sandbox Code Playgroud)
引用手册页:
-r, --real
print the real ID instead of the effective ID, with -ugG
Run Code Online (Sandbox Code Playgroud)