Setting Default File Permissions
The umask (user file-creation mask) determines the default permissions assigned to newly created files and directories.
How umask Works
umask is a subtraction mechanism based on the maximum possible permissions:
- Max Permissions for Files: 666 (
rw-rw-rw-). Files cannot naturally have execute (x) permissions for security. - Max Permissions for Directories: 777 (
rwxrwxrwx). Directories need execute (x) to allow entry/traversal.
The umask value is subtracted from the maximum possible value.
Common umask Values
- 0022: This is common for multi-user servers. (777 - 022 = 755 for directories; 666 - 022 = 644 for files).
755: Owner gets full access, Group and Others get read/execute.
- 0002: Common for single-user home directories or secure setups. (777 - 002 = 775 for directories; 666 - 002 = 664 for files).
775: Owner and Group get full access, Others get read/execute.
Viewing and Setting umask
bash $ umask 0022
$ umask 0002