Linux 读取文件:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20124444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:24:50  来源:igfitidea点击:

reading a file: permission denied

linux

提问by Rick

I have set these permissions on a file:

我在文件上设置了这些权限:

----r--r-x 1 rick rick       50 Nov 20 18:39 hello_world

Now I try to open the file with user rick who is a member of the group rick.

现在,我尝试使用 rick 组成员的用户 rick 打开该文件。

rick@ubuntu:~/Documents$ cat hello_world
cat: hello_world: Permission denied

Why can't he read it?

为什么他读不懂?

采纳答案by zwol

Since the accessing process has userid "rick", onlythe owning-user permissions, which forbid reading, are checked. Only if the accessing process does nothave the same userid as the owner of the file will the kernel consider the possibility that it might be a member of the file's group.

由于访问进程有用户标识“rick”,因此检查禁止读取的拥有用户权限。只有在访问过程中也不能有相同的用户标识作为文件的所有者将内核考虑的可能性,这可能是该文件的组的成员。

Any process running as the owning user of a file can use the chmodsystem call to set its permission bits to whatever they want, so denying read or write access to the owning user is ineffective as a securitymeasure, but it can still be a useful safetymeasure. In other words, you can use the permission bits to prevent a file from being clobbered by its owning user by accident, but not on purpose.

任何作为文件所有者用户运行的进程都可以使用chmod系统调用将其权限位设置为任何他们想要的,因此拒绝所有者用户的读或写访问作为一种安全措施是无效的,但它仍然是一种有用的安全措施措施。换句话说,您可以使用权限位来防止文件被其拥有者无意中破坏,但不是故意破坏。

回答by fedorqui 'SO stop harming'

Your permissions are set now to readjust for "group" and "others".

您的权限现在设置为read仅用于“组”和“其他”。

As said in the comments, the user rickdoes belong to the group, but what counts is the fact that is the owner, so the permissions checked are the ones on the first column, which happen to be ---, that is 0. Hence, the groupis not taken into consideration.

正如评论中所说,用户rick确实属于该组,但重要的是所有者这一事实,因此检查的权限是第一列上的权限,恰好是---,即0。因此,group不考虑。

Change the permissions to something more normal :)

将权限更改为更正常的内容:)

chmod 644 hello_world

Then you will be able to read it. As the permissions go as follows:

然后你就可以阅读了。由于权限如下:

4 read
2 write
1 execute

6means read + write.

6表示读+写。