If i edit the file from a remote server via text editor (geany, sublime text..etc) locally, the file user and group will changed to the logged user.

Let say if I accessing the remote file with root user (using caja file manager)

Before root user edit: file member:admin

After root user edit: file root:root

How do I prevent this?

UPDATE If I edit the files remotely with VIM, the owner and group remain the same. So, I think maybe it is related to the text editor??

  • If you edit an existing file it shouldn't change anything. – 123 Jul 14 '16 at 14:40
  • That's what I thought, but the truth is opposite. – dev-jim Jul 14 '16 at 14:42
  • Since this depends on the editor and you didn't focus the question on a specific editor, I've closed your question as a duplicate of a generic one about this issue. If you want to know how to force ownership preservation on a specific editor, first make sure that you understand that this may result in data loss, then edit your question to focus on that specific editor. But you should not edit files as root! – Gilles 'SO- stop being evil' Jul 14 '16 at 22:56

In this case , root has permission to write to the directory, so root's editor writes a file /path/file.tmp (or some similar name) then moves the new file to /path/file. Since root just created the file, it is owned by root. This is how some of the editors work by default.

For more help about editors and preserving file permissions etc , see the link below:

"...instruct your editor to edit the file in place. With Vim, set the backupcopy option to yes, if that isn't the default on your system. With Emacs, set the backup-by-copying variable to t ..."

More Help

| improve this answer | |
  • No, I am editing existing files not created new one. – dev-jim Jul 14 '16 at 14:44
  • yes , i haven't said that you are creating new ones , it is how the editors work. as said in the answer , the editor creates a new temp file itself...because it's not editing the file in-place – Ijaz Ahmad Khan Jul 14 '16 at 14:44
  • I got what you meant. So, this is text editor related issue. I am using geany or sublime text, not sure how to configure them. – dev-jim Jul 14 '16 at 14:48
  • then that is a different question :) i haven't used geany or sublime – Ijaz Ahmad Khan Jul 14 '16 at 15:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.