Setup a folder so that new files created in it inherit default permissions and group

6 thoughts on “Setup a folder so that new files created in it inherit default permissions and group

  1. Hi Jonathan,
    It works for stick the group, however not for the permissions. There is any command that allows to inherit the permissions of the parent folder for new files?
    drwxrws–T parent_directory
    -rw——- child_new_file (Stick the group but not the permissions)

    1. Hi Jenny,

      Great question. The command chmod g+s ensures that the group ownership is inherited by new files and folders created in it.

      What you are looking for is a bit trickier as file permissions are not inherited, but are set when created. You can achieve this using POSIX ACLs

      setfacl -d -m u::rwX,g::rwX,o::- /path/to/parent

      Explained:
      -m modifying the
      -d default ACLs
      rw give the files read/write permissions. You can change these to what you need.
      X uppercase means only directories will receive the +x bit

      Also for reference:
      u is the user
      g is the group
      o means other

  2. Thanks for your article, very useful. If there are already files and folders in /path/to/folder should you run `chmod -R g+s /path/to/folder` to ensure that sub-folders also have the sticky bit set?

    1. Hi Jacob,

      Thanks for your question. No, it shouldn’t be necessary unless you plan on updating those files too and want the permissions to stay.

Leave a Reply

Your email address will not be published.

Previous post B2B vs B2C – are you talking your customers language?
Next post Ubuntu Rackspace, how to set up a server qualified domain name?