What Is Umask and How Does It Work in Linux?

The user mask, commonly known as umask, is a Linux environment setting that determines the default permission bits assigned to newly created files and directories. Instead of granting permissions directly, umask acts as a filter that restricts specific access rights—read, write, or execute—from standard system-wide defaults. Understanding how umask calculates these values is essential for managing file security and multi-user environments in the Linux operating system.

Base Permissions in Linux

When a new file or directory is generated, the operating system starts with standard baseline permissions before the umask is applied:

How Umask Determines Permissions

The umask value represents the permissions you want to remove or mask out from the base permissions. It uses standard octal permission values:

In basic practice, the effective permission is calculated by subtracting the umask value from the base permission.

Example Calculation with Umask 022

The most common default umask on Linux distributions is 0022 (or simply 022):

Example Calculation with Umask 027

In environments requiring stricter privacy, a umask of 027 is often applied:

(Note: Under the hood, Linux uses a bitwise NOT operation followed by a bitwise AND between the base permission and the mask: Mode = Base & (~Umask).)

Viewing and Setting Umask

To view your current shell session's umask, open a terminal and run:

umask

To display the active permissions symbolically rather than in octal format, run:

umask -S

To temporarily change the umask for your active shell session, pass the desired octal value:

umask 0077

With 0077, any new file created in that session will receive 0600 (rw-------) permissions, making it completely private to the file owner.

Making Umask Changes Permanent

To ensure a custom umask applies automatically whenever a user logs in, the command can be declared inside user profile configuration files: