setuid 位结果
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,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".
您不能在 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.