检查用户是否有 *nix 中文件的权限
出于好奇。我一直在思考 *nix 中常见的不同访问模型和基于 windows nt 的系统中常见的访问模型。
是否有任何命令或 api 来检查文件对于与登录用户不同的用户是否可读、可执行等。例如: http://www.php.net/manual/en/function。 is-executable.php 或者 使用 Python 检查 Linux 中的文件权限 但对于执行用户有权查看的任何用户。
有什么理由不应该找到这样的功能吗?
Out of curiosity. I've been thinking about the different access models often seen in *nix and the one seen in windows nt based systems.
Is there any command or api to check if a file is readable, executable etc for a user different than the logged in user. For instance something like:
http://www.php.net/manual/en/function.is-executable.php
or
Checking File Permissions in Linux with Python
But for any user that the executing user has permission to see.
Is there any reason why such a function should not be found?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 *nix 中,用户对文件的权限是否可以由 2 个属性确定:文件的全局权限和组权限。如果全局权限设置为 r、w 或 x,那么任何用户当然都对该文件拥有这些权限。同样,如果用户是指定为文件的组所有者的组的成员,并且这些权限是在组级别设置的,则用户将再次拥有该文件的该权限。当然,您需要确保用户对文件绝对路径中的所有目录具有适当的权限。当然,root 可以访问任何文件,无论权限或所有权如何。
因此,对于任何特定文件,通过查看文件权限和用户的组成员身份,可以相对容易地确定特定用户是否具有该文件的权限。
In *nix whether a user's permissions on a file can be determined by 2 attributes: the world and group permissions on a file. If the world permissions are set for r,w, or x than of course any user will have those rights on that file. Similarly if the user is a member of the group that is specified as the group owner of the file, and those permissions are set on the group level then again the user will have that right on the file. Of course you need to be sure the user the appropriate rights on all directories in the absolute path of the file. And, of course, root can access any file regardless of the permissions or ownerships.
So for any particular file it is relatively easy to determine whether a specific user has permissions on that file by looking at the file permissions and the group memberships of the user.