| |

LFCS 38 ๐Ÿง Default Permissions โ€” umask

โฑ๏ธ Estimated read: 14 min | |

Every file and directory created on a Linux system starts with a default set of permissions. The shell sets them, the applications inherit them, and the values come from a mask called the umask. The umask is not a permission itself; it is a mask that subtracts bits from the maximum allowed permissions. A file created with a umask of 022 ends up with 644, and a directory ends up with 755. The umask is one of the few settings that applies to every file a user creates without the user doing anything, which is why it matters for security and for collaboration.

Key point: The umask is subtractive. It removes permission bits from a default. The default for files is 666 (no execute bit), and the default for directories is 777. The umask is subtracted from these values. The result is the permission the new file or directory receives.


Why umask exists

The default-permission problem. A new file must have some permission. The kernel does not guess; it applies the default. The umask is how the user or the administrator controls what that default is.

The execute-bit problem. A new file should not be executable by default. A text file that is executable is a potential accident, and a downloaded script that is executable is a potential attack. The file default of 666 never includes the execute bit, and the umask does not add it.

The security problem. A user whose umask is 000 creates world-readable and world-writable files. A user whose umask is 077 creates files that only the user can read. The difference is a single shell setting, and the wrong setting exposes the user’s data.

The collaboration problem. A team that shares a directory needs the files created in it to be readable by the group. A umask of 002 produces 664 files and 775 directories, which give the group read and write access. A umask of 022 produces 644 files, which the group can read but not write.

The consistency problem. Different users on the same system have different umasks. A file created by one user may be readable by the group, and a file created by another may not. The umask is set per user, and the default comes from the system configuration.

The inheritance problem. A process inherits the umask from its parent. A shell that sets the umask affects every process the shell starts, and those processes affect their children. The umask is inherited, not inherited from a configuration file that the child reads.

The per-session problem. The umask is set per shell session. A user who logs in with a login shell gets the umask from the login configuration. A user who runs a subshell or a non-login shell may get a different value, depending on the shell and the configuration.


a. The umask calculation

The umask is a three- or four-digit octal number. The calculation subtracts it from the default permissions.

The defaults

TypeDefaultReason
File666Read and write for all, no execute
Directory777Read, write, and execute for all

The default is the maximum a new file or directory could have. The umask removes the bits that should not be set.

The subtraction

The subtraction is a bitwise AND with the complement of the umask. In practice, the result is the default with the umask’s bits cleared.

File:      666
umask:     022
result:    644

The 2 bits (write) are cleared from the group and others.
The 6 bits (read and write) are unchanged for the user.

The common umasks

umaskFilesDirectoriesMeaning
022644755Owner read-write, others read
002664775Owner read-write, group read-write
027640750Owner read-write, group read
077600700Owner only
007660770Owner and group, no others
000666777World-writable (dangerous)

The calculation table

umaskFile DefaultFile ResultDirectory DefaultDirectory Result
022666644777755
002666664777775
027666640777750
077666600777700
007666660777770
000666666777777

The bit positions

The umask has three digits, one per class.

DigitClassBits
FirstUser4 = read, 2 = write, 1 = execute
SecondGroup4 = read, 2 = write, 1 = execute
ThirdOthers4 = read, 2 = write, 1 = execute

A 2 in the group position clears the group write bit. A 7 in the others position clears the read, write, and execute bits.

The four-digit form

A four-digit umask includes the special bits. The first digit is the setuid (4), setgid (2), and sticky (1) bits.

umask 0022

The leading 0 is the special-bits digit. The 022 is the standard mask. The special bits are rarely set in the umask.

The subtraction is not arithmetic

The calculation is a bitwise operation, not an arithmetic subtraction. The default minus the umask is the result in most cases, but the bitwise AND is the actual operation.

666 & ~022 = 644
777 & ~022 = 755

The ~022 is the complement of the umask, and the AND clears the masked bits.


b. The umask command

The umask command displays or sets the mask.

The display

umask
# 0022

The command prints the current umask in octal. The leading 0 is the special-bits digit.

The symbolic display

umask -S
# u=rwx,g=rx,o=rx

The -S flag prints the mask in symbolic form. The symbolic form shows what the permissions will be, not what is masked.

The symbolic set

umask u=rwx,g=rx,o=

The symbolic form sets the umask by specifying the allowed permissions for each class. The o= clears the others bits.

The octal set

umask 022
umask 077
umask 027

The octal form sets the mask directly. The setting applies to the current shell and every process it starts.

The session scope

The umask is a shell setting. It applies to the current session and every child process. When the shell exits, the setting is lost unless it is in a configuration file.

The login configuration

The umask is set in the shell’s startup files. For Bash, the files are /etc/profile, /etc/bash.bashrc, ~/.bash_profile, ~/.bashrc, and ~/.profile. The system-wide file sets the default, and the user file overrides it.

# /etc/profile
umask 022

# ~/.bashrc
umask 077

The pam_umask module

On systems with PAM, the pam_umask module sets the umask for the login session. The value is read from /etc/login.defs or from the user’s entry in /etc/passwd.

# /etc/login.defs
UMASK 022

The module applies the umask to the login session, and the shell’s configuration files may override it.

The per-user umask

The umask can be set per user in /etc/passwd or in the user’s shell configuration.

# /etc/passwd
alice:x:1000:1000:Alice:/home/alice:/bin/bash

The umask is not a field in /etc/passwd. The per-user setting comes from the shell configuration, the pam_umask module, or a custom script.

The effective umask

The effective umask is the value in effect when the file is created. The value is inherited from the parent process, and the shell’s configuration sets it for interactive sessions.

umask
# 0022

touch file.txt
ls -l file.txt
# -rw-r--r-- ... file.txt

The file is created with 644 because the umask is 022.


c. The common umask settings

The umask is chosen based on the user’s role and the system’s requirements. The common settings are 022, 002, 027, and 077.

The 022 umask

The 022 umask is the default on most systems. It produces 644 files and 755 directories. The owner has full access, and the group and others have read access.

umask 022
touch file.txt
mkdir dir
ls -l file.txt
ls -ld dir
# -rw-r--r-- ... file.txt
# drwxr-xr-x ... dir

The setting is appropriate for a single-user workstation and for files that are meant to be shared read-only.

The 002 umask

The 002 umask produces 664 files and 775 directories. The group has read and write access, and the others have read access.

umask 002
touch file.txt
mkdir dir
ls -l file.txt
ls -ld dir
# -rw-rw-r-- ... file.txt
# drwxrwxr-x ... dir

The setting is appropriate for a shared team directory where the group needs to edit the files.

The 027 umask

The 027 umask produces 640 files and 750 directories. The group has read access, and the others have no access.

umask 027
touch file.txt
mkdir dir
ls -l file.txt
ls -ld dir
# -rw-r----- ... file.txt
# drwxr-x--- ... dir

The setting is appropriate for a server where the files are read by the group but not by the world.

The 077 umask

The 077 umask produces 600 files and 700 directories. Only the owner has access.

umask 077
touch file.txt
mkdir dir
ls -l file.txt
ls -ld dir
# -rw------- ... file.txt
# drwx------ ... dir

The setting is appropriate for a user who works with sensitive data, such as SSH keys or credentials.

The 007 umask

The 007 umask produces 660 files and 770 directories. The owner and the group have read and write access, and the others have no access.

umask 007
touch file.txt
mkdir dir
ls -l file.txt
ls -ld dir
# -rw-rw---- ... file.txt
# drwxrwx--- ... dir

The setting is appropriate for a shared directory where the group is trusted and the world is not.

The setting table

Use CaseumaskFilesDirectories
Default022644755
Shared team002664775
Server, group-readable027640750
Private data077600700
Group-only007660770
World-writable000666777

The setgid interaction

The setgid bit on a directory makes new files inherit the directory’s group. The umask does not affect the group ownership; it affects the permission bits.

chmod 2775 /srv/project
umask 002
touch /srv/project/file.txt
ls -l /srv/project/file.txt
# -rw-rw-r-- alice developers file.txt

The group is developers (from the setgid bit), and the permissions are 664 (from the umask).

The default ACL interaction

A default ACL on a directory overrides the umask for the files created inside it. The setfacl command sets the default ACL.

setfacl -d -m g:developers:rwx /srv/project
touch /srv/project/file.txt
getfacl /srv/project/file.txt
# group:developers:rwx

The default ACL takes precedence over the umask, which is the mechanism for a more granular permission scheme.


Complete Example Session

# ============================================
# PART 1: THE CURRENT UMASK
# ============================================

umask
# 0022

umask -S
# u=rwx,g=rx,o=rx

# ============================================
# PART 2: THE FILE CREATION
# ============================================

touch file.txt
ls -l file.txt
# -rw-r--r-- 1 alice alice 0 ... file.txt

# ============================================
# PART 3: THE DIRECTORY CREATION
# ============================================

mkdir dir
ls -ld dir
# drwxr-xr-x 2 alice alice 4096 ... dir

# ============================================
# PART 4: THE 077 UMASK
# ============================================

umask 077
touch private.txt
ls -l private.txt
# -rw------- 1 alice alice 0 ... private.txt

mkdir private-dir
ls -ld private-dir
# drwx------ 2 alice alice 4096 ... private-dir

# ============================================
# PART 5: THE 002 UMASK
# ============================================

umask 002
touch shared.txt
ls -l shared.txt
# -rw-rw-r-- 1 alice alice 0 ... shared.txt

# ============================================
# PART 6: THE 027 UMASK
# ============================================

umask 027
touch restricted.txt
ls -l restricted.txt
# -rw-r----- 1 alice alice 0 ... restricted.txt

# ============================================
# PART 7: THE PERSISTENT SETTING
# ============================================

echo 'umask 077' >> ~/.bashrc
# The setting applies to every new shell.

# ============================================
# PART 8: THE SYSTEM-WIDE SETTING
# ============================================

sudo echo 'umask 022' >> /etc/profile.d/umask.sh
# The setting applies to every login.

# ============================================
# PART 9: THE LOGIN.DEFS SETTING
# ============================================

grep UMASK /etc/login.defs
# UMASK 022

# The pam_umask module reads this value.

# ============================================
# PART 10: THE CALCULATION
# ============================================

umask 022
# File:      666 - 022 = 644
# Directory: 777 - 022 = 755

umask 077
# File:      666 - 077 = 600
# Directory: 777 - 077 = 700

The ten parts showed the current umask, the file creation, the directory creation, the 077 umask, the 002 umask, the 027 umask, the persistent setting, the system-wide setting, the login.defs setting, and the calculation.


Quick Reference

The umask Calculation

DefaultumaskResult
666022644
666002664
666027640
666077600
777022755
777002775
777027750
777077700

The umask Command

CommandPurpose
umaskShow the current umask
umask -SShow the symbolic form
umask 022Set the umask
umask u=rwx,g=rx,o=Set symbolically

The Configuration Files

FileScope
/etc/profileSystem-wide login
/etc/profile.d/*.shSystem-wide login
/etc/bash.bashrcSystem-wide interactive
~/.bash_profilePer-user login
~/.bashrcPer-user interactive
~/.profilePer-user login
/etc/login.defsThe pam_umask default

The Common Settings

umaskUse Case
022Default
002Shared team
027Server, group-readable
077Private data
007Group-only

The File Types

TypeDefaultReason
File666No execute by default
Directory777Execute required to enter

Best Practices

โœ… Do This:

# Set the umask in the shell configuration.
echo 'umask 022' >> ~/.bashrc  # โœ…

# Use 077 for sensitive data.
umask 077  # โœ…

# Use 002 for shared team directories.
umask 002  # โœ…

# Verify the umask before creating files.
umask  # โœ…

# Set the system-wide default.
echo 'umask 022' | sudo tee /etc/profile.d/umask.sh  # โœ…

# Check the result with ls -l.
touch file.txt && ls -l file.txt  # โœ…

# Use a default ACL for more granular control.
setfacl -d -m g:developers:rwx /srv/project  # โœ…

โŒ Don’t Do This:

# Don't use umask 000.
umask 000  # โŒ World-writable files

# Don't expect the umask to affect existing files.
umask 077  # โŒ Only affects new files

# Don't set the umask in a non-login shell only.
# The setting is lost when the shell exits.  # โŒ

# Don't forget the umask is inherited.
# A child process inherits the parent's value.  # โŒ

# Don't use the umask to make a file executable.
# The execute bit is never set by the umask.  # โŒ

# Don't rely on the umask for security alone.
# Use the file permissions as the primary control.  # โŒ

Common Pitfalls

PitfallWhy It HappensFix
Files are world-readableumask 022Use 077 for private
Group cannot writeumask 022Use 002 for shared
Execute bit missingDefault is 666chmod +x
Setting not persistentSet in the shell onlyAdd to ~/.bashrc
Different value in loginNon-login shellSet in all config files
Setting lost on logoutSession scopeUse the config file
Default ACL ignoredNo default ACLUse setfacl -d

Real-World Examples

1. Show the Umask

umask

2. Symbolic Display

umask -S

3. Set to 022

umask 022

4. Set to 077

umask 077

5. Set to 002

umask 002

6. Persistent Setting

echo 'umask 022' >> ~/.bashrc

7. System-Wide Setting

echo 'umask 022' | sudo tee /etc/profile.d/umask.sh

8. The login.defs

grep UMASK /etc/login.defs

9. Verify the Result

touch file.txt && ls -l file.txt

10. Default ACL

setfacl -d -m g:developers:rwx /srv/project

Visual

The umask Calculation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE umask CALCULATION                                     โ”‚
โ”‚                                                            โ”‚
โ”‚  FILE                                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  Default:  666  (rw-rw-rw-)                       โ”‚     โ”‚
โ”‚  โ”‚  umask:    022  (----w--w-)                       โ”‚     โ”‚
โ”‚  โ”‚  Result:   644  (rw-r--r--)                       โ”‚     โ”‚
โ”‚  โ”‚                                                   โ”‚     โ”‚
โ”‚  โ”‚  The write bits are cleared from the group        โ”‚     โ”‚
โ”‚  โ”‚  and the others. The read bits are unchanged.     โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                                                            โ”‚
โ”‚  DIRECTORY                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  Default:  777  (rwxrwxrwx)                       โ”‚     โ”‚
โ”‚  โ”‚  umask:    022  (----w--w-)                       โ”‚     โ”‚
โ”‚  โ”‚  Result:   755  (rwxr-xr-x)                       โ”‚     โ”‚
โ”‚  โ”‚                                                   โ”‚     โ”‚
โ”‚  โ”‚  The write bits are cleared from the group        โ”‚     โ”‚
โ”‚  โ”‚  and the others. The read and execute bits        โ”‚     โ”‚
โ”‚  โ”‚  are unchanged.                                   โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Common umasks

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE COMMON umasks                                         โ”‚
โ”‚                                                            โ”‚
โ”‚  umask 022                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  Files:  644  (rw-r--r--)                         โ”‚     โ”‚
โ”‚  โ”‚  Dirs:   755  (rwxr-xr-x)                         โ”‚     โ”‚
โ”‚  โ”‚  Use:    Default, single-user workstation         โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                                                            โ”‚
โ”‚  umask 002                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  Files:  664  (rw-rw-r--)                         โ”‚     โ”‚
โ”‚  โ”‚  Dirs:   775  (rwxrwxr-x)                         โ”‚     โ”‚
โ”‚  โ”‚  Use:    Shared team directory                    โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                                                            โ”‚
โ”‚  umask 077                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  Files:  600  (rw-------)                         โ”‚     โ”‚
โ”‚  โ”‚  Dirs:   700  (rwx------)                         โ”‚     โ”‚
โ”‚  โ”‚  Use:    Private data, SSH keys                   โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                                                            โ”‚
โ”‚  umask 027                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  Files:  640  (rw-r-----)                         โ”‚     โ”‚
โ”‚  โ”‚  Dirs:   750  (rwxr-x---)                         โ”‚     โ”‚
โ”‚  โ”‚  Use:    Server, group-readable                   โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The umask Inheritance

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE umask INHERITANCE                                     โ”‚
โ”‚                                                            โ”‚
โ”‚  LOGIN SHELL                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  umask 022                                        โ”‚     โ”‚
โ”‚  โ”‚    (from /etc/profile)                            โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                           โ”‚                                โ”‚
โ”‚                           โ”‚  Inherited                    โ”‚
โ”‚                           v                                โ”‚
โ”‚  INTERACTIVE SHELL                                         โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  umask 022                                        โ”‚     โ”‚
โ”‚  โ”‚    (from ~/.bashrc)                               โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                           โ”‚                                โ”‚
โ”‚                           โ”‚  Inherited                    โ”‚
โ”‚                           v                                โ”‚
โ”‚  CHILD PROCESS                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  umask 022                                        โ”‚     โ”‚
โ”‚  โ”‚    (inherited from the shell)                     โ”‚     โ”‚
โ”‚  โ”‚                                                   โ”‚     โ”‚
โ”‚  โ”‚  Files created: 644, directories: 755             โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The setgid Interaction

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE setgid INTERACTION                                    โ”‚
โ”‚                                                            โ”‚
โ”‚  /srv/project  (drwxrwsr-x, group: developers)             โ”‚
โ”‚                                                            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚  alice (primary group: alice) creates a file.     โ”‚     โ”‚
โ”‚  โ”‚                                                   โ”‚     โ”‚
โ”‚  โ”‚  Without setgid:                                  โ”‚     โ”‚
โ”‚  โ”‚    -rw-r--r-- alice alice file.txt (umask 022)    โ”‚     โ”‚
โ”‚  โ”‚                                                   โ”‚     โ”‚
โ”‚  โ”‚  With setgid on the directory:                    โ”‚     โ”‚
โ”‚  โ”‚    -rw-r--r-- alice developers file.txt           โ”‚     โ”‚
โ”‚  โ”‚                                                   โ”‚     โ”‚
โ”‚  โ”‚  The group is inherited from the directory.       โ”‚     โ”‚
โ”‚  โ”‚  The umask still controls the permission bits.    โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
umaskThe default permission mask
Default file666
Default directory777
umask 022644 files, 755 directories
umask 002664 files, 775 directories
umask 027640 files, 750 directories
umask 077600 files, 700 directories
umaskThe command to show or set
umask -SThe symbolic display
/etc/profile.d/The system-wide configuration
~/.bashrcThe per-user configuration

Key takeaways:

  • The umask is a subtractive mask. It removes permission bits from the default. The default for a file is 666 and for a directory is 777. The umask is subtracted from the default to produce the actual permission.
  • The execute bit is never set by the umask. The file default of 666 does not include the execute bit, and the umask does not add it. A file that must be executable requires an explicit chmod +x.
  • The umask is per session and inherited. The setting applies to the current shell and every process it starts. The value is inherited from the parent, and the shell’s configuration files set it for interactive sessions.
  • The common umasks serve different purposes. 022 is the default for single-user workstations, 002 is for shared team directories, 027 is for servers, and 077 is for private data.
  • The umask is set in the shell configuration files. The system-wide setting is in /etc/profile and /etc/profile.d/. The per-user setting is in ~/.bashrc or ~/.bash_profile. The pam_umask module reads /etc/login.defs for the login session.
  • The setgid bit and the umask work together. The setgid bit on a directory determines the group of new files, and the umask determines their permission bits. The two settings are independent.
  • A default ACL overrides the umask. A default ACL on a directory sets the permissions for new files inside it, regardless of the umask. The setfacl -d command sets the default ACL.
  • The umask is a default, not a security control. The umask controls the permissions of new files, but the file permissions themselves are the primary control. A user who needs a file to be private should set the permissions explicitly, not rely on the umask.

Remember: The umask is the mask that determines the default permissions of every file and directory a user creates. It is subtracted from the default of 666 for files and 777 for directories, and the result is the actual permission. The umask is set per session and inherited by child processes, and it is configured in the shell’s startup files. The common values are 022, 002, 027, and 077, each suited to a different use case. The setgid bit and the default ACL interact with the umask, and the combination determines the final permissions. The result is a system where every new file starts with a predictable permission, and where the default is chosen by the user or the administrator.


Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!