Skip to main content

Understanding the `umask` Scope

In Linux, the umask value is a property of a user's environment, not of a particular directory or file. It sets the default permissions for all new files and directories created by that user, regardless of where they are created.

Here are some key points to understand:

  1. User Session Scope: When you set a umask value, it is applicable for the duration of the session for the user who set it. If the user logs out, the umask value is reset to its default value unless explicitly set in a startup script like .bashrc or .profile.

  2. Inheritance: Processes inherit the umask value from their parent process. This means that if you set a umask in a shell and then start a program from that shell, the program inherits the same umask value.

  3. No Retroactive Changes: Changing the umask does not retroactively alter the permissions of already existing files or directories. It only affects new files and directories created thereafter.

  4. Global vs Local Settings: System-wide default umask values can usually be set in files like /etc/login.defs or /etc/profile, affecting all users. However, individual users can still change their umask in their own shell sessions.

  5. Script and Service Context: When running scripts or services, the umask value may be set specifically within the script or service definition. This ensures that files and directories created by the service have the intended permissions.

  6. Temporary Changes: You can also set a umask value for a single command by using a one-liner like umask 027; touch new_file. After the command executes, the original umask will still be in place for subsequent commands.

In summary, umask is not about targeting specific directories or files; rather, it's about setting an environment property that determines how future files and directories will be created in terms of their permission sets.

What Can You Do Next 🙏😊

If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.

YouTube @cloudaffle