Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
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.
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?'
Yes.
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.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.