Rick
Rick

Reputation: 1274

reading a file: permission denied

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@ubuntu:~/Documents$ cat hello_world
cat: hello_world: Permission denied

Why can't he read it?

Upvotes: 6

Views: 35031

Answers (2)

fedorqui
fedorqui

Reputation: 289635

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

As said in the comments, the user rick does 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 group is not taken into consideration.

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

6 means read + write.

Upvotes: 10

zwol
zwol

Reputation: 140569

Since the accessing process has userid "rick", only the owning-user permissions, which forbid reading, are checked. Only if the accessing process does not have 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.

Any process running as the owning user of a file can use the chmod system call to set its permission bits to whatever they want, so denying read or write access to the owning user is ineffective as a security measure, but it can still be a useful safety measure. 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.

Upvotes: 9

Related Questions