What is the purpose of umask?

The umask (user file creation mask) is a command used in Unix-like operating systems to set default permissions for newly created files and directories. Its primary purpose is to define which permissions should be masked (or removed) from the default permissions that would otherwise be assigned.

Key Points about umask:

  1. Default Permissions: When a new file or directory is created, it typically has default permissions (e.g., 666 for files and 777 for directories). The umask value is subtracted from these defaults to determine the actual permissions.

  2. Masking Permissions: The umask value specifies which permissions to remove:

    • Read (r) = 4
    • Write (w) = 2
    • Execute (x) = 1

    For example, a umask of 022 would result in:

    • Files: 666 - 022 = 644 (rw-r--r--)
    • Directories: 777 - 022 = 755 (rwxr-xr-x)
  3. Security: By setting a umask, users can ensure that newly created files and directories have appropriate permissions, enhancing security by preventing unauthorized access.

  4. User-Specific: Each user can set their own umask value, allowing for customized permission settings based on individual needs.

To view the current umask value, you can simply run the command:

umask

To set a new umask, you can use:

umask 027

This would set the umask to 027, affecting the permissions of newly created files and directories.

0 Comments

no data
Be the first to share your comment!