How does umask affect permissions?

QuestionsQuestions8 SkillsProBasic Files OperationsSep, 16 2025
0191

The umask (user file creation mask) in Linux affects the default permissions assigned to newly created files and directories. It specifies which permission bits should be "masked out" or removed when a file or directory is created. Here's how it works:

  1. Default Permissions:

    • For directories, the default permissions are typically 777 (rwxrwxrwx).
    • For files, the default permissions are typically 666 (rw-rw-rw-), since files do not usually need execute permissions by default.
  2. Applying umask:
    The umask value is subtracted from the default permissions to determine the actual permissions for the newly created file or directory. The umask value is specified in octal format.

    For example:

    • If the umask is set to 022, the permissions for a new directory would be calculated as follows:

      • Default permissions for a directory: 777
      • Subtract 022 (umask): 777 - 022 = 755
      • Resulting permissions: 755 (rwxr-xr-x)
    • For a new file with the same umask:

      • Default permissions for a file: 666
      • Subtract 022 (umask): 666 - 022 = 644
      • Resulting permissions: 644 (rw-r--r--)
  3. Common umask Values:

    • 000: No restrictions; files and directories are created with full permissions.
    • 022: Common default; allows the owner full permissions while restricting group and others to read and execute.
    • 027: Restricts group access; owner has full permissions, while group has no write access.

You can check the current umask value by running:

umask

To change the umask value for the current session, you can use:

umask new_value

Understanding umask is important for managing file and directory permissions effectively in a multi-user environment.

0 Comments

no data
Be the first to share your comment!