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 byfind
for each directorychmod 644 {}
specifies the command that will be executed byfind
for each file{}
is replaced by the path;
the semicolon tellsfind
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 offind
Related Topics
Sanitize Environment with Command or Bash Script
Does Linux Kill Background Processes If We Close the Terminal from Which It Has Started
How I Should Run My Golang Process in Background
Difference Between Checkout and Export in Svn
Shared Libraries: Windows VS Linux Method
Why Does Perf Stat Show "Stalled-Cycles-Backend" as <Not Supported>
How to Create a Waveform Image of an Mp3 in Linux
How to Check Syslog in Bash on Linux
How to Tell Which Unix Shell I am Using
Remove the Last Page of a PDF File Using PDFtk
Unix Command to List Files Containing String But *Not* Containing Another String
Setting Node_Env for Node.Js + Expressjs Application as a Daemon Under Ubuntu
Changing Name of the Video While Downloading via Youtube-Dl
Building Linux Kernel on MAC Os X
When Grep "\\" Xxfile I Got "Trailing Backslash"
Count the Number of Executable Files in Bash
Choosing Between Multiple Executables with Same Name in Linux