2014-02-13

Sharing file edit ability between two users in Linux

I create two Desktop users, “beggar” and “mr” using graphical tool “Users and Groups”.

By default every user have its own group with the same name, and some other groups.
You can check it with command

$id {userName}

$ id mr
uid=1001(mr) gid=1001(mr) groups=1001(mr)mr

$ id beggar
uid=1000(beggar) gid=1000(beggar) groups=1000(beggar),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),112(lpadmin),
119(sambashare)

By default when user creates new file, file permission is:
 read/write for owner and read only for group and others.
We have to change it to:
 read/write for owner and group and readonly for others.
Then users in the same group can edit files.

There is two configuration files.
Applies for files created by command line   ~/.bashrc
Applies for files created by X applications   ~/.profile
Add this line

umask 002

at the end of the file or create these files if they not exists. Do it for both users.

Permission Table:
Umask  Created Files   Created Directories
-------------------------------------------------------------
000  666 (rw-rw-rw-)     777  (rwxrwxrwx)
002  664 (rw-rw-r--)  775  (rwxrwxr-x)
022  644 (rw-r--r--)         755  (rwxr-xr-x)
027  640 (rw-r-----)         750  (rwxr-x---)
077  600 (rw-------)          700  (rwx------)
277  400 (r--------)            500  (r-x------)
-------------------------------------------------------------


I will use command usermod to add user to a group with these options:

-G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups

So, if I want to allow user “beggar” edit files created by user “mr”, I need to add user “beggar” to group “mr”.

$usermod -a -G mr beggar

Now “beggar” can edit files created by “mr”
And the opposite,  if I want to allow user “mr” edit files created by user “beggar”,  I need to add user “mr” to group “beggar”

$usermod -a -G beggar mr

then “mr” can edit files created by “beggar”

Before you can test it, you have to LOGOUT and LOGIN!

From now on  “beggar” and  “mr” can edit each others files! :)
Happy ending!

No comments:

Post a Comment