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:
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, theumask
value is reset to its default value unless explicitly set in a startup script like.bashrc
or.profile
.Inheritance: Processes inherit the
umask
value from their parent process. This means that if you set aumask
in a shell and then start a program from that shell, the program inherits the sameumask
value.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.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 theirumask
in their own shell sessions.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.Temporary Changes: You can also set a
umask
value for a single command by using a one-liner likeumask 027; touch new_file
. After the command executes, the originalumask
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.