LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   change of owner and group owner of a file belongs to diff user ? (https://www.linuxquestions.org/questions/linux-newbie-8/change-of-owner-and-group-owner-of-a-file-belongs-to-diff-user-4175545147/)

somorg 06-12-2015 02:42 AM

change of owner and group owner of a file belongs to diff user ?
 
Can anyone explain ?

Hi,
(Red Hat Linux 7)
#mkdir /doc
#chmod 777 /doc
user1$ cd /doc
user1$ touch file1
{here the owner and group owner of the file is user1}

user2$ cd /doc
user2$ vim file1
{user2 is able to add content and save the file.}

1. After user2 edited the file1 with "vim" the owner of the file get changed why?
2. file1 was created my user1 and having 664 perm by default and user1 is the owner and groupowner of the file. How user2 was able to edit it with the file having only read perm for others ?

Habitual 06-12-2015 09:44 AM

give us the output of
Code:

ls -al /doc
please.

ongte 06-12-2015 09:50 AM

This is because the directory permissions allowed user2 to overwrite the file. Although user2 only had read permisson on the file, when saving it could not be saved in-place, so it used the write permission on the directory to overwrite the file, thats why the owner changes. Write permission on a directory allows creation and deletion of files in that directory regardless of the file permission itself.

jpollard 06-14-2015 09:11 AM

Quote:

Originally Posted by somorg (Post 5375958)
Can anyone explain ?

Hi,
(Red Hat Linux 7)
#mkdir /doc
#chmod 777 /doc
user1$ cd /doc
user1$ touch file1
{here the owner and group owner of the file is user1}

user2$ cd /doc
user2$ vim file1
{user2 is able to add content and save the file.}

1. After user2 edited the file1 with "vim" the owner of the file get changed why?

The owner changed because vim deleted the original file (or renamed it to a backup) and created a new file.
Quote:

2. file1 was created my user1 and having 664 perm by default and user1 is the owner and groupowner of the file. How user2 was able to edit it with the file having only read perm for others ?
a. The directory permissions 777 allows ANYONE to delete a file. There are no protections.
b. user2 was allowed to read the file, and create a new file. From item "a", that user is also allowed to delete/rename the file before creating a new file there.

You should look into what the "sticky" bit is for (for example, how it is used for /tmp).

BTW, you might also look into using "git" for documentation version control... That would allow you to determine who can make changes, as well as resolve collision when two or more make edits to the same file without loosing edits. It also allows you a "undo" to make it simple to revert changes.

There is also a "gitfs" that can be used to provide a filesystem access to the data (https://github.com/PressLabs/gitfs and scroll down to see what it is).


All times are GMT -5. The time now is 06:06 PM.