Skip to content

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 contents
  • w: Write – Modify contents
  • x: Execute – Run as a program (for files), or enter/list directory (for folders)

You can view permissions using:

ls -l filename

Example output:

-rwxr-xr--  1 jdoe projectgroup  4096 Jun 10 12:00 script.sh

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:

umask 0002

To make this setting persistent, add it to your .bashrc file:

echo 'umask 0002' >> ~/.bashrc
source ~/.bashrc

⚠️ 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:

  1. Request a group from sysadmins and add project members.
  2. Create a shared folder in a common location (like /project or group scratch).
  3. Change group ownership:
chgrp <groupname> <folder>
  1. Set the SGID bit so that all files inherit the folder's group:
chmod g+s <folder>
  1. 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 or chown on your home directory.
  • Be cautious when syncing between Linux and Windows — case-sensitivity and file system differences can cause data loss or duplicates.

External Resources