Linux file permissions question
Hello all,
When I've given files permissions such as 775 so members of the same group can read, write and execute a file I've always assumed that they could write to the file itself and also to the file's permissions. However now I've tried it this doesn't seem to be the case. I can't find any references on the net specifically explaining this though. Is it true to say that 'Only the owner or root can change a file's permissions even if other users have write permissions?' The test I did was something along the lines of: As user1: sudo groupadd test-group sudo usermod -G test-group -a user1 sudo usermod -G test-group -a user2 touch test-file1 newgrp test-group touch test-file2 chmod 775 test-file* ls -l test-file* -rwxrwxr-- 1 user1 user1 0 Nov 26 15:39 test-file1 -rwxrwxr-- 1 user1 test-group 0 Nov 26 15:40 test-file2 Then as user2: newgrp test-group cd /home/user1 chmod 777 test-file1 <- Expected to fail chmod 777 test-file1 <- Expected to succeed Results: chmod: changing permissions of `test-file1': Operation not permitted chmod: changing permissions of `test-file2': Operation not permitted Any help, such as a link to confirm my understanding is correct would be most appreciated! Rj :-) |
I noticed that user2 was trying to work with the file in /home/user1. I wonder if this is the root of the problem.
Myself, I've created a new directory in /home for both users to read and write in. |
Quote:
I haven't ever looked on the cause why this is this way. However, note that on tipical filesystems the attributes are inserted in the file system, not in the file itself. So, granting you access (even write access) into the file doesn't necessarily grant you any right over the attributes, which are stored into a separate place. |
It make sense. If anyone who had write permissions could alter the file permissions, then anyone in your group could (accidentally or otherwise) change your file from 775 to 777. Or, they could do 470 and lock you out from making changes. If you had wanted the file to be 777, you would have done so yourself. Anything else would be a security risk.
|
Yup. That's the whole point of permissions. If anyone with write permission could override them why set them in first place.
|
Thanks for all your help, it seems as though this is the way it works although I'll try Cichlid's idea just to double check. I have to admit I'm very surprised that nobody has mentioned any documentation which explains what I consider to be a very fundamental part of Linux security, very odd!
Rj :confused: |
This is a good reference page for how Linux permissions work - http://www.comptechdoc.org/os/linux/..._ugfilesp.html
|
All times are GMT -5. The time now is 04:46 PM. |