Find the answer to your Linux question:
Results 1 to 5 of 5
I'm having trouble figuring out how to create a directory so that no matter who creates a file in the directory, as long as they belong to the group that ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    3

    File permisions for a group

    I'm having trouble figuring out how to create a directory so that no matter who creates a file in the directory, as long as they belong to the group that owns the directory, there files are set to +rw for the group.

    Example as root:

    addgroup marketing
    usermod -a -G marketing someuser
    mkdir /marketing
    chown :marketing /marketing
    chmod g+s marketing marketing
    chmod -R g+rw /marketing
    su someuser
    cd /marketing
    touch test

    it seems to me that the file test should have the permissions -rwxrw-r-- but
    that isnt what I get. I get -rwxr--r-- and it's driving me crazy that I can't get this to work... PLEASE HELP

    MH

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    The permissions that a file has when created are determined by a user's umask. The umask works as follows:
    Code:
    permissions = 0666 & ~umask
    In plain English, the umask is an octal number subtracted from 0666 in order to determine the initial permissions of a file created by a user. As far as I know, an individual user's umask is the only way to influence the permissions of a file created by that user. You may see your umask or change it by employing the umask command.

    Your code does not work because chmod -R applies the chmod to all files that exist presently in that directory. It does not apply special magic to the directory that affects future files.

    Something similar to what you are trying to accomplish would be to have a cronjob run every minute and apply your chmod -R g+rw command to the directory. This is not quite the same (the file will not have the permissions from creation), but is the closest I can think of (the file will have the permissions no later than one minute after creation).
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    3
    It just doesnt make sense that a file can be set to +rw for a group automatically on creation. How the heck do multiple people share files on linux?

  4. #4
    Just Joined!
    Join Date
    Aug 2009
    Posts
    76
    I'm not thoroughly acquainted with group permissions, but shouldnt a command like:

    chgrp -R marketing /marketing

    also be applied?

    I would think, that the permissions settings of new files would be inherited from the directory. Correct me if i'm wrong.

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    @Zeroangel

    No. Files do not inherit the permissions of the directory they were created under. Using chmod -R (or any other -R command) applies the command to all files that exist in the directory at the time the command is run: they cannot affect future files.

    @mhoney

    A common way of sharing files is to make your files readable by other people, if not writable. That way, they can always copy the file and do what they want, submitting a patch back to the master.

    Alternatively, you could create a master user for the marketing group and make his primary group the marketing group. Make his umask 0006. Now all files created by this user will be readable and writable by the marketing group only. Creating a file could be done by:
    Code:
    sudo -u marketingmaster touch /marketing/file
    or
    su marketingmaster -c touch /marketing/file
    And then modified by the user.

    You could also look into something called Access Control Lists (ACLs). I don't know much about them, but they allow for much finer permissions. Enabling them does require kernel modification, however.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...