When creating a new file or directory linux applies default set of permissions. umask commands lets you change default permissions Who does it apply to ? Owner, Group and Others just like permissions How to view ?
1
2
3
umask
umask -S # Displays current mask as symbolic value
umask -p # Displays current mask value with prefix umask
How to calculate umask value ?
- umask value is calculated by subtracting umask value from default permissions
- System default value permissions are 777(rwxrwxrwx) for folders and 666?(rw-rw-rw-) for files
- Default mask for non-root user is 002 changing folder permissions to 775(rwxrwxr-x) and file permissions to 664 (rw-rw-r–)
- Default mask for root user is 022, changing folder permissions to 755(rwxr-xr-x) and file permissions to 644 (rw-r–r–)
How to change umask value ?
- non-persistent = # umask 0022
- Persistent = add a line umask 0022 to any of the file below
1
2
3
vi ~/.bash_profile # for individual user
vi /etc/bashrc # systemwide interactive and noninteractive shell ( e.g console, vnc )
vi /etc/profile # systemwide interactive shell
Note: When files are copied or created via ssh, it uses default mask to apply permissions for a new file . If -P flag is used then it will use local permissions.
umask calculator: https://wintelguy.com/umask-calc.pl All Possible umask values: https://www.linuxtrainingacademy.com/all-umasks/