Course contentsShow
← Linux
Lesson 351 of 1,8194. Advanced Access Control ModelsFree lesson

Default File Creation Masks and Process Environments

Control the initialization state of filesystem objects using process-level permission filters.

In this lesson, you will learn how the umask command allows you to define the base security posture of every file and directory your process creates.

When you create a new file, the system doesn't just assign it random permissions. Instead, it starts with a "default maximum" (usually 666 for files and 777 for directories) and then subtracts the bits defined by your process's file mode creation mask, or umask.

Think of the umask as a "deny" filter. If the mask is set to 022, it tells the system: "When creating new files, do not give group members or others write permissions."

How it works in practice

The umask is inherited by your shell process from the parent environment. Every child process you launch—whether it's a text editor, a compiler, or a database script—will respect this mask. Because it is a process-level environment variable, you can adjust it on the fly to control how your applications interact with the filesystem.

Try checking your current mask by typing umask in your terminal. You will likely see 0022. To test how this affects object creation, run the following:

# Set a restrictive mask
umask 077

# Create a new file
touch secret.txt

# Check the resulting permissions
ls -l secret.txt

Because your mask is 077, the system strips all access for group and others. Your secret.txt will result in -rw-------, meaning only you can read or write to it.

This mechanism is vital for maintaining a secure environment. By setting the umask at the start of a user session or within a service startup script, you ensure that any files created by your processes are born with the correct security constraints, preventing "permission leakage" where sensitive data might be accidentally exposed to other users on the system.

Key Takeaway: The umask acts as a mandatory filter that subtracts specific permission bits from newly created files and directories, ensuring that every process operates within your defined security boundaries by default.