File and Folder Permissions in Linux
Understanding Linux file permissions is crucial for system stability, data security, and effective collaboration. Misconfigured permissions can result in scripts failing, users being locked out, or unintended data exposure.
Basics of Permissions
Each file or folder in Linux has three permission sets:
- Owner (user): The person who created the file.
- Group: A set of users sharing the same group rights.
- Others: All other users.
Each set can have the following permissions:
r
: Read – View contentsw
: Write – Modify contentsx
: Execute – Run as a program (for files), or enter/list directory (for folders)
You can view permissions using:
Example output:
Default Permissions and umask
When a new file or folder is created:
- The owner gets read and write permissions.
- The group is usually the user’s primary group (or inherited if SGID bit is set).
- The others get read-only access.
You can control default permissions using the umask setting:
To make this setting persistent, add it to your .bashrc
file:
⚠️ Do NOT use umask 0000
or chmod 777
unless absolutely necessary. Avoid changing permissions on your home folder — it must remain private.
Collaborating in Shared Folders
To set up a shared project folder where multiple users can edit files:
- Request a group from sysadmins and add project members.
- Create a shared folder in a common location (like
/project
or group scratch). - Change group ownership:
- Set the SGID bit so that all files inherit the folder's group:
- Ensure every user has
umask 0002
in place.
This ensures collaborative write access without affecting private files.
Special Cases
- x-bit on files: Marks them as executable.
- x-bit on folders: Allows directory listing.
Note: CIFS (Windows) shares like the R-disk do not follow Linux permissions. Ignore chmod or ls -l output on such systems.
Avoiding Permission Issues
- Never apply recursive
chmod
orchown
on your home directory. - Be cautious when syncing between Linux and Windows — case-sensitivity and file system differences can cause data loss or duplicates.