umask
created some confusion, so after reading some documentation I got a clear idea.
umask: [ u => User ]
- When we create files or directories, those files got some default permission.
- mask work exactly as do in photo editing tools. It does not set permissions, instead it remove given permissions.
Default_permission = pre-defined_initial_permission – umask_permission
Pre-defined permission are fixed and cannot be changed.
- for directory: 777
- for file : 666
Default umask permissions for user:
- root user : 0022
- normal user : 0002
So Without any change in default umask permissions:
+---------------------------------------------------+
| User | Directory | File |
|---------------+-----------------------+-----------|
| |
| <user> | 777 - x => y | 666 - x => y |
| root | 777 - 022 => 755 | 666 - 022 => 644 |
| normal | 777 - 002 => 775 | 666 - 002 => 664 |
| |
| |
| NB: 1st bit (0) of umask values: not effect |
| permission so it ignored from calculation. |
| |
| |
+---------------------------------------------------+
Umask permission change can be 2 type:
- Temporary : by
umask
command, closing shell reset to default.
- Permanent : By setting UMASK value in:
- User Level:
~/.profile
, or .bashrc
- Globally:
/etc/profile
, /etc/bashrc
, or /etc/login.defs
NB: umask
substract permissions from user not from particular directory.
- umask: set permission before created.
- chmod: Change permission after created.
$ umask --help
-S : makes the output symbolic; otherwise an octal number is output
-p : if MODE is omitted, output in a form that may be reused as input
$ umask # Show umask of user
$ umask -S # Show umask of user as symbol instead of number
$ umask 0022 # Set Umask.
umask
only takes one argument -- it applies to the user, not any specific directory. And it masks out permission, not sets them. 666 masks outrw
, but files do not getx
by default. 333 masks outwx
and leavesr
. Directories getx
by default (for them, it means searchable).