bitlvl
EN

umask calculator

A umask removes permission bits from new files. Type one to see the result, or tick the permissions you want new files and directories to have.

Bits removed
r
w
x
Owner
Group
Others

How umask works

When a program creates a file it asks for a mode, almost always 666 (rw-rw-rw-) for files and 777 for directories. The kernel then clears every bit that is set in the process's umask. With the usual 022, the write bits for group and others are removed: files become 644, directories 755. With 077 everything for group and others goes: 600 and 700. The mask can only remove permissions, never add; a file never gets execute from the umask, because 666 never had it.

The arithmetic is mode & ~umask, a bitwise AND with the inverted mask, not subtraction, so umask 027 on 666 gives 640, not 639.

Common values

umaskFilesDirectoriesUsed for
022644755Default on most distributions; others can read.
002664775Debian/Ubuntu for users with a private group; group members can write.
077600700Private by default: servers, home directories with secrets.
027640750Group can read, others nothing; common hardening baseline (CIS).

Where it is set

  • Shell: umask prints it, umask 027 sets it for the session; put it in ~/.profile or /etc/profile. umask -S shows it symbolically.
  • Login: /etc/login.defs (UMASK) and pam_umask set the value before the shell starts; /etc/profile on Debian derives it from whether the user has a private group.
  • systemd services: UMask=0077 in the [Service] section; services do not read shell profiles.
  • cron: jobs run with 022 regardless of the user's shell settings; set it inside the script.
  • Docker: the container's default is 022; change it in the entrypoint or with umask in the command.

Questions

Why do my new files have 644 when I want 664?

Your umask is 022. Set umask 002 (and make sure the directory’s group is the one you want, with the setgid bit on the directory so new files inherit it).

Does umask affect chmod?

No. chmod sets exact bits. umask only applies when a file is created without an explicit mode, which is nearly always.

Why does the directory get execute but the file does not?

Directories are created with 777 before the mask, files with 666. Execute on a directory means “can enter it”; files need chmod +x explicitly.

Is a four-digit umask different?

A leading 0 (0022) is just octal notation. The first digit would mask setuid/setgid/sticky, which creating processes never request, so it has no effect in practice.