I have a project with a number of files that I created in Linux.
And I needed to give another user write permission on them. So I created a "dev" group of which he and I are members and changed the ownership of the files to this group.
A typical file now has these permissions :
-rw-rw-r-- 1 phil dev 5617 Jul 14 15:45 profile.html
However, when I edit the file profile.html it reverts to me like this, and my colleague loses the ability to edit.
-rw-rw-r-- 1 phil phil 5617 Jul 14 15:45 profile.html
How do I avoid it reverting like this? Was changing the ownership the wrong thing to do? Or was it done with the wrong options? Or is this to do with my editor (emacs) configuration?
On the containing folder you'll want to change the group to be dev and then use mark it set-gid.
The set gid bit makes files created in that folder to inherit the group of the folder as well as marking the setgid bit on any new folders. You'll want to be careful when moving files into the directory as that will preserve their existing permissions.
You can use the setgid bit on a directory to preserve group ownerships by children.
You could also mount the filesystem ( assuming ext2/3 ) with the grpid mount option which will make it so whenever you create a new file in a directory, it will make the group owner the same as the parent directory. So then you would just make it so the directory that these files exist in are owned by the group 'dev'.
To remount it if it is the root partition (example):
From 'man mount 8':
Default behavior for emacs is to create the backup file by renaming. From the emacs manual:
There are several ways to change this.
Or emacs specific:
So, add to your .emacs:
My preference is actually 'newgrp dev', as it is an explicit switch from "personal" mode (the files I edit are just mine), to group dev mode (the files I now edit are shared amongst the group).