File owner changed after editing it

172 views Asked by At
[root@MGWSDT_FEWS ~]# ll file 
-rw-r--r-- 1 root bill 0 Aug 14 17:28 file
[root@MGWSDT_FEWS ~]# su - bill
$ vi /root/file

I edited this file and wq!

Now bill becomes the file owner:

$ ll /root/file
-rw-r--r-- 1 bill bill 16 Aug 14 17:29 /root/file

Why? So strange!

1

There are 1 answers

2
exussum On

bill cant edit the file. hess part of the group which only has read access.

So switching to bill you would expect a permissions error when you try and write.

In this case bill is also the directory owner, so whats actually happening is the file is being removed, and recreated now with bill as the owner.

:w  !sudo tee % 

would write as root and keep the permissions