umask

The builtin, and the per-process setting it controls, that lists which permission bits are removed from every new file and directory.

In more detail

New files start from 666 and directories from 777, minus the umask. With the common umask 022, files come out 644 and directories 755; with 077 nobody else gets any access. It is inherited by child processes.

Examples

umask 077
umask  # prints 0022 on many systems
Go: os.WriteFile(path, data, 0o600) is filtered through the umask
Programs usually request 666 for files and 777 for directories, and the umask clears the bits it names. With umask 027, a new file becomes 640 and a new directory 750: group write and all access for others are removed. It is a subtraction, not a final mode, so the result depends on what was requested.
request=666 umask=027 result=640 is the calculation for a new regular file.

Related terms

Taught in

References

Certification courses