Linux Directory Permissions for Different Groups

Linux directory permissions for different groups

Well, I know this is relatively old, but twalberg is correct: there's actually a relatively easy way to accomplish this with POSIX ACL's. They've existed since the late 90's/early 2000's so I don't know why more people don't use them.

How to do it: Do as you've already done, then simply execute this command:

# setfacl -m g:god:rwx public private

and in one command you get what you're wanting. You'll spend forever trying to figure out how to do it using ONLY traditional unix permissions.

Mikic's advice may still be good (depending on what you're trying to accomplish), and it might be more straight forward to reference as few groups as possible in your permissions (or maybe you want it to be apparent that "chris" isn't a regular user, but an administrative one, again it depends on what you want to construct).

I offered something closer to what you're trying to accomplish, because there may be situations where you're trying to give a secondary user/group access to a directory but you don't want to choose between "chris" not getting access to these two directories and "chris" getting access to all those other files and directories "pub" and "priv" might have access to. With ACL's you don't have to make those choices, which is why they were added and are now a core part of most Unix (and BSD and Linux) platforms.

Members of group can't access directory in linux

Directories require executable access to enter/see contents. So if you wanted a group to have access privileges to a directory chmod -R 775 assignment/ should work.

How to set permission to a directory with multiple groups with ansible?

Since the underlying operating system seems to be Linux, the answer to your question

How to set permission to a directory with multiple groups?

will be you can't do that. At least not in that way. Ansible can configure only what is available.

So you may have a look into the basic concepts of how to manage Linux permissions for users, groups, and others.

In example

  • Linux group permissions
  • Granting write permissions to a group to a folder
  • How does group permissions work?

and maybe put the fluentd user into app_group. An other approach could be introducing Access Control Lists (ACL).

In example

  • How can I give permissions of files to multiple groups?
  • Two Groups Separate Permissions, One Directory?

What could override group permissions on a linux directory?

Check whether you are currently in that group by running id - if you haven't logged in (or su'ed) since adding that group membership, you won't have it yet.

Linux: Set permission only to directories

Use find's -type option to limit actions to files and directories. Use the -o option to specify alternate actions for different types, so you only have to run find once, rather than separately for each type.

find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +

How do I change permissions for a folder and its subfolders/files?

The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Some splainin': (thanks @tobbez)

  • chmod 755 {} specifies the command that will be executed by find for each directory
  • chmod 644 {} specifies the command that will be executed by find for each file
  • {} is replaced by the path
  • ; the semicolon tells find that this is the end of the command it's supposed to execute
  • \; the semicolon is escaped, otherwise it would be interpreted by the shell instead of find


Related Topics



Leave a reply



Submit