简体   繁体   English

检查用户是否对* nix中的文件具有权限

[英]Checking if user has permissions for file in *nix

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. 我一直在考虑在* nix和基于Windows nt的系统中经常看到的不同访问模型。

Is there any command or api to check if a file is readable, executable etc for a user different than the logged in user. 是否有任何命令或api检查与登录用户不同的用户文件是否可读,可执行等。 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. 例如,诸如: http : //www.php.net/manual/en/function.is-executable.php使用Python在Linux中检查文件权限,但是对于执行用户有权查看的任何用户。

Is there any reason why such a function should not be found? 有什么原因不能找到这样的功能?

In *nix whether a user's permissions on a file can be determined by 2 attributes: the world and group permissions on a file. 在* nix中,用户对文件的权限是否可以由2个属性确定:文件的世界和组权限。 If the world permissions are set for r,w, or x than of course any user will have those rights on that file. 如果为r,w或x设置了世界权限,那么任何用户都将对该文件拥有这些权限。 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. 而且,当然,root用户可以访问任何文件,而不管其权限或所有权如何。

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. 因此,对于任何特定文件,通过查看文件许可权和用户的组成员身份来确定特定用户是否对该文件具有许可权相对容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM