setuid 位结果

发布于 2024-10-03 08:25:32 字数 167 浏览 0 评论 0原文

我有一个 shell 脚本,我想设置 uid 位。 我将所有者设置为 root 并设置 uid 位。 我在 shell 中添加了“whoami”来检查它是否正常工作 但是当我执行脚本时,whoami 返回用户名,而不是 root。 那么这是错误的,对吧?如果 uid 设置正确的话我应该已经获得 root 权限了,对吗?

I have a shell script that I want to set uid bit.
I set the owner to root and set uid bit.
I added 'whoami'in the shell to check if it is working properly
but when I executed the script, whoami returned user's name, not root.
Then this is wrong, right? I should have gotten root if uid was set correctly, right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月野兔 2024-10-10 08:25:32

不,setuid 位不会更改登录用户,它会更改脚本运行的有效用户 (euid)。

此外,setuid 位不适用于脚本。

如果您希望由权限较低的用户以 root 身份执行脚本,我建议您查看“su”或“sudo”。

No, the setuid bit does NOT change the logged in user, it changes the effective user (euid) the script runs as.

Furthermore, setuid bits do not work on scripts.

If you want a script to be executed as root by less privileged users, I recommend to look into "su" or "sudo".

想你的星星会说话 2024-10-10 08:25:32

您不能在 shell 脚本中使用 setuid 位。 shell 解析 shebang 行以确定要执行的程序,然后启动该程序程序而不关心脚本上设置的 setuid 位。

请参阅https://serverfault.com/questions/8449/cannot-set-uid-on -shell 脚本

You can't use the setuid bit with shell scripts. The shell parses the shebang line to determine the program to execute, then launches that program without caring the slightest about the setuid bit set on the script.

See https://serverfault.com/questions/8449/cannot-set-uid-on-shell-scripts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文