When working with shared folders in Linux systems, you'll often need to grant specific permissions to particular groups. A common scenario is giving read, write, and execute (rwx) access to a development team's group while maintaining other permission restrictions.
The command you tried:
chmod -R g+rwx docs
modifies group permissions but doesn't target a specific group. This affects whatever group is currently associated with the folder, which might not be your intended devs
group.
To properly grant permissions to the devs
group, you need two steps:
# First, change the group ownership to devs
sudo chgrp -R devs docs
# Then apply the permissions
sudo chmod -R g+rwx docs
After running these commands, verify the changes with:
ls -ld docs
ls -l docs
The output should show group ownership set to devs
and permissions including rwx
for the group.
For enterprise environments, you might want to:
# Set the SGID bit to maintain group ownership for new files
sudo chmod -R g+s docs
# Or set ACLs for more granular control
sudo setfacl -R -m g:devs:rwx docs
- Ensure the
devs
group exists (getent group devs
) - Check your user has permission to modify group ownership (typically requires sudo)
- Remember that execute permission is needed to traverse directories
When managing file permissions in Linux, you need to consider three levels of access: user
, group
, and others
. The command you tried (chmod -R g+rwx docs
) modifies group permissions but doesn't specify which group should receive these permissions.
There are actually two distinct operations needed here:
# First, change the group ownership of the folder
sudo chgrp -R devs docs
# Then apply the permissions to the group
chmod -R g+rwx docs
Always verify your changes with these commands:
ls -ld docs # Check single folder
ls -l docs # Check contents
groups $(whoami) # Verify your group membership
You can combine both operations using the chown
command with permission syntax:
sudo chown -R :devs docs && chmod -R g+rwx docs
If you still can't access the folder after these changes:
- The user must be member of 'devs' group (use
usermod -aG devs username
) - You may need to logout/login or use
newgrp devs
- Check for filesystem ACLs with
getfacl docs
Let's say you have a web project with multiple developers:
# Create shared project directory
sudo mkdir /var/www/project
sudo chown root:devs /var/www/project
sudo chmod 2775 /var/www/project # 2 enables setgid