5.4.3.4 Ensure default user umask in /etc/profile.d is configured

Information

The user file-creation mode mask ( umask ) is used to determine the file permission for newly created directories and files. In Linux, the default permissions for any newly created directory is 0777 ( rwxrwxrwx ), and for any newly created file it is 0666 ( rw-rw-rw- ). The umask modifies the default Linux permissions by restricting (masking) these permissions. The umask is not simply subtracted but is processed bitwise. Bits set in the umask are cleared in the resulting file mode.

umask can be set with either Octal or Symbolic values:

- Octal (Numeric) Value - Represented by either three or four digits. ie umask 0027 or umask 027 . If a four digit umask is used, the first digit is ignored. The remaining three digits effect the resulting permissions for user, group, and world/other respectively.
- Symbolic Value - Represented by a comma separated list for User u, group g, and world/other o . The permissions listed are not masked by umask . ie a umask set by umask u=rwx,g=rx,o= is the Symbolic equivalent of the Octal umask 027 . This umask would set a newly created directory with file mode drwxr-x--- and a newly created file with file mode rw-r-----.

Order of precedence:

- A file in /etc/profile.d/ ending in .sh - This will override any other system-wide umask setting in the file /etc/profile
- The file /etc/profile
- A file in /usr/etc/profile.d/ ending in *.sh will override any other system-wide umask setting in the default vendor configuration file /usr/etc/profile
- The default vendor configuration file /usr/etc/profile

Setting a secure default value for umask ensures that users make a conscious choice about their file permissions. A permissive umask value could result in directories or files with excessive permissions that can be read and/or written to by unauthorized users.

Satisfies: SRG-OS-000480-GPOS-00228, SRG-OS-000480-GPOS-00227

Solution

Create or edit a file in /etc/profile.d/ ending in *.sh and add or modify the following line:

umask 027

Example:

# printf '%s\n' "" "umask 027" >> /etc/profile.d/60-default_umask.sh

Notes:

- This method only applies to bash and shell. If other shells are supported on the system, it is recommended that their configuration files also are checked
- If the pam_umask.so module is going to be used to set umask, ensure that it's not being overridden by another setting. Refer to the PAM_UMASK(8) man page for more information

See Also

https://workbench.cisecurity.org/benchmarks/26236