By default, when regular users create files, the permissions are set to "rw-rw-r--," and when they create directories, the permissions are set to "rwxrwxr-x." You might wonder why these default permissions are set this way, and can you change them? The umask command allows you to modify these default permissions.
For example, let's take a look at what umask displays when you run it:
$ umask 0002 |
umask | Default File Permissions | Default Directory Permissions |
000 |
rw- rw- rw- |
rwx rwx rwx |
002 |
rw- rw- r-- |
rwx rwx r-x |
022 |
rw- r-- r-- |
rwx r-x r-x |
027 |
rw- r-- --- |
rwx r-x --- |
077 |
rw- --- --- |
rwx --- --- |
277 |
r-- --- --- |
r-x --- --- |
For instance, when umask displays "0022," it means that when regular users create files, the permissions will be "rw-r--r--," and for directories, they will be "rwxr-xr-x."
When running umask as the root user, the output is typically "0022," resulting in files with "rw-r--r--" permissions and directories with "rwxr-xr-x" permissions by default.
If you want to change the default permissions for creating files or directories, you can use the umask # command followed by a mask number (where # is a number from the table above).
For example: $ umask 0 |