Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading a file: permission denied

Tags:

linux

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?

like image 277
Rick Avatar asked Nov 21 '13 15:11

Rick


2 Answers

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.

like image 176
zwol Avatar answered Sep 18 '22 20:09

zwol


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.

like image 26
fedorqui 'SO stop harming' Avatar answered Sep 19 '22 20:09

fedorqui 'SO stop harming'