What are umask settings?

QuestionsQuestions8 SkillsProDec, 17 2025
0162

That's an excellent follow-up question, as umask directly relates to directory (and file) permissions, which we just touched upon with mkdir -m!

umask stands for "user file creation mask". It's a fundamental concept in Linux/Unix file permissions.

Here's a breakdown:

  1. Default Permissions: When you create a new file or directory, the system assigns it a set of default permissions.

    • For files, the theoretical maximum permission is usually 666 (read/write for owner, group, and others).
    • For directories, the theoretical maximum permission is usually 777 (read/write/execute for owner, group, and others). (Directories need execute permission to be entered/navigated.)
  2. The Role of umask: The umask setting acts as a "mask" that removes specific permissions from these default maximums when a new file or directory is created. It's like a filter.

  3. How it Works (Subtraction):

    • You usually see umask as a three-digit octal number, like 0022 or 0002. The leading 0 is often ignored for calculation.

    • To find the actual permissions of a newly created item, you subtract the umask value from the maximum default permissions.

    • Example with umask 022:

      • For a new directory:

        • Maximum default: 777
        • umask: -022
        • Resulting permissions: 755 (rwxr-xr-x) — Owner can read/write/execute, Group can read/execute, Others can read/execute.
      • For a new file:

        • Maximum default: 666
        • umask: -022
        • Resulting permissions: 644 (rw-r--r--) — Owner can read/write, Group can read, Others can read.
  4. Why umask?

    • Security: It's a security measure. Rather than making every new file and directory fully open (777 or 666), umask ensures that by default, they have more restrictive permissions, preventing unwanted access.
    • Consistency: It provides a consistent way to set default permissions across a system or for a specific user.

How to check your current umask:
You can simply type umask in your terminal:

umask

The typical output is often 0002 or 0022. In LabEx, it's usually 0002.

If your umask is 0002:

  • New directories get 777 - 002 = 775 (rwxrwxr-x)
  • New files get 666 - 002 = 664 (rw-rw-r--)

Understanding umask helps you know why your newly created files and directories have the permissions they do by default, and how mkdir -m can override those defaults.

Does this explanation of umask clarify its role for you?

0 Comments

no data
Be the first to share your comment!