5.5.4 Ensure default user umask is 027 or more restrictive
Audit#
Run the following to verify:
- A default user umask is set to enforce a newly created directories's permissions to be 750 (drwxr-x---), and a newly created file's permissions be 640 (rw-r-----), or more restrictive
- No less restrictive System Wide umask is set
Run the following script to verify that a default user umask is set enforcing a newly created directories's permissions to be 750 (drwxr-x---), and a newly created file's permissions be 640 (rw-r-----), or more restrictive:
Verify output is: "Default user umask is set"
Run the following to verify that no less restrictive system wide umask is set:
# grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}(,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* /etc/bash.bashrc*
No file should be returned
Remediation#
Run the following command and remove or modify the umask of any returned files:
# grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}(,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* /etc/bash.bashrc*
Follow one of the following methods to set the default user umask:
Edit /etc/login.defs and edit the UMASK and USERGROUPS_ENAB lines as follows:
Edit /etc/pam.d/common-session and add or edit the following:
OR
Configure umask in one of the following files: * A file in the /etc/profile.d/ directory ending in .sh * /etc/profile * /etc/bash.bashrc
Example: /etc/profile.d/set_umask.sh
Note: 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.
Default Value:
UMASK 022