Information
The user file-creation mode mask ( umask ) determines the file permission for newly created directories and files. In FreeBSD, the default permission for any newly created directory is 0755 ( rwxr-xr-x ), and for any newly created file, it is 0644 ( rw-r--r-- ). The umask modifies the default FreeBSD 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 three or four digits. ie umask 022 or umask 027 . If a four-digit umask is used, the first digit is ignored. The remaining three digits affect 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 . i.e. 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-----.
The default umask can use the login class capability database /etc/login.conf module or in a System Wide Shell Configuration File . The user creating the directories or files has the discretion of changing the permissions via the chmod command or choosing a different default umask by adding the umask command into a User Shell Configuration File, ( .cshrc or .shrc ), in their home directory.
Setting the default umask:
- Login class capability database:
- will set the umask according to the system default in /etc/login.conf and user settings, solving the problem of different umask settings with different shells, display managers, remote sessions, etc.
- The umask=<mask> value in the /etc/login.conf file is interpreted as Octal
- System Wide Shell Configuration File :
- /etc/profile - used to set system-wide environmental variables on users' shells. The variables are sometimes the same ones in the .profile ; however, this file is used to set an initial PATH or PS1 for all shell users of the system. is only executed for interactive login shells, or shells executed with the --login parameter.
- /etc/profile.d - /etc/profile will execute the scripts within /etc/profile.d/*.sh . It is recommended to place your configuration in a shell script within /etc/profile.d to set your own system-wide environmental variables.
- /etc/csh.cshrc - System-wide version of .cshrc.
User Shell Configuration Files:
- ~/.profile - This is executed to configure your shell before the initial command prompt. Is only read by login shells.
- ~/.shrc - Is executed for interactive shells if the user's shell is set to /bin/sh . only read by a shell that's both interactive and non-login
- ~/.cshrc - Is executed for interactive shells if the user's shell is set to /bin/csh . only read by a shell that's both interactive and non-login
umask is set by order of precedence. If umask is set in multiple locations, this order of precedence will determine the system's default umask.
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
- In the file /etc/login.conf
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.
Solution
In case proper umask is not configured system-wide necessary measurements should be taken to define them in /etc/login.conf or system-wide shell configurations like a file in /etc/profile.d/*.sh or /etc/csh.cshrc.
Note:
- This method only applies to Bourne Again shell and C Shell. If other shells are supported on the system, it is recommended that their configuration files also be checked