0
[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!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
qiuweidong
  • 17
  • 1
  • 3
  • some explanation http://unix.stackexchange.com/questions/58880/how-does-vim-steal-root-owned-files – exussum Aug 14 '13 at 09:37
  • This question appears to be off-topic because it is about *nix; could be fit for unix.se or superuser. – Marijn Aug 14 '13 at 09:45
  • agreed with Marijn, but does this happen with others editors like emacs or nano? – Soosh Aug 14 '13 at 09:49

1 Answers1

0

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

exussum
  • 18,275
  • 8
  • 32
  • 65
  • [root@MGWSDT_FEWS ~]# ll -i aaa 13370492 -rw-r--r-- 1 root bill 0 Aug 15 09:31 aaa [root@MGWSDT_FEWS ~]# su - bill -bash-3.2$ vi aaa -bash-3.2$ ll -i aaa 13370492 -rw-r--r-- 1 bill bill 6 Aug 15 09:32 aaa You can see that inode doesn't change, so why you said the original file was removed and recreated? Another question is bill doesn't have 'w' access, why it can still edit the file with wq!? – qiuweidong Aug 15 '13 at 01:23
  • you need w access to the directory to remove the file. Inode doesn't change because him unlinks and writes straight away without closing the file descriptor – exussum Aug 15 '13 at 06:31