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:
User Session Scope: When you set a
umaskvalue, it is applicable for the duration of the session for the user who set it. If the user logs out, the
umaskvalue is reset to its default value unless explicitly set in a startup script like
Inheritance: Processes inherit the
umaskvalue from their parent process. This means that if you set a
umaskin a shell and then start a program from that shell, the program inherits the same
No Retroactive Changes: Changing the
umaskdoes not retroactively alter the permissions of already existing files or directories. It only affects new files and directories created thereafter.
Global vs Local Settings: System-wide default
umaskvalues can usually be set in files like
/etc/profile, affecting all users. However, individual users can still change their
umaskin their own shell sessions.
Script and Service Context: When running scripts or services, the
umaskvalue may be set specifically within the script or service definition. This ensures that files and directories created by the service have the intended permissions.
Temporary Changes: You can also set a
umaskvalue for a single command by using a one-liner like
umask 027; touch new_file. After the command executes, the original
umaskwill still be in place for subsequent commands.
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.