Umask permission

When setting up a umask value for example 002 and 022, is it necessary to change it in /etc/profile and /etc/bashrc? Or it can be set only in either of the two? What’s the difference in setting it in both and in only one of them?

IIRC, it is enough to do it in a *.sh file that you drop into /etc/profile.d/.

The bash has login and non-login shells. The former sources /etc/profile (and ~/.bash_profile).
The non-login shells tend to be started by the login shell, so they do inherit what it got.

If you do look at the ~/.bash_profile (and ~/.bashrc), you probably see that even the login shell will (indirectly) source the bashrc. Therefore, if the /etc/profile.d/ does not do the job, then go for the bashrc.

If it’s to any help… This is what I ended up doing when I wanted 022 as my standard - without interfering with the other defaults.

# umask initialization script (sh)
# /etc/profile.d/
# umask 002:    775/664
# umask 022:    755/644
# - - -
# Set umask to 022 for users with uid/gid 1000 and over, to get standard
# file permissions. By default, users with uid/gid 200 and over get umask 002

if [ $UID -gt 999 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 022