The umask command sets the default file permissions for newly created files and directories. It works by masking (removing) permissions from the default permission set, providing system-wide security control over file creation.
Key Concepts
- Permission Mask: Bits that are subtracted from default permissions
- Default Permissions: Files (666), Directories (777)
- Octal Notation: Three-digit numbers representing owner, group, other
- Symbolic Notation: Letters (u,g,o) with operators (+,-,=)
- Session Scope: umask applies to current shell session and child processes
Command Syntax
umask [options] [mode]
- Without arguments: displays current umask
- With mode: sets new umask value
- Mode can be octal (022) or symbolic (u=rwx,g=rx,o=rx)
Common Options
-p - Output in format reusable as input
-S - Display in symbolic notation instead of octal
Practical Examples
Example 1: Check current umask
|
|
Shows current mask removes write for group/others
Example 2: Set restrictive umask
|
|
Only owner has read/write permissions
Example 3: Set permissive umask
|
|
Group has full access, others read/execute
Example 4: Using symbolic notation
|
|
Removes all permissions for others
Permission Calculation
|
|
Use Cases
- Security hardening: Set restrictive umask (077) for sensitive environments
- Shared directories: Use permissive umask (002) for team collaboration
- Web servers: Moderate umask (022) for public content
- System scripts: Ensure consistent permissions across deployments
Persistent Configuration
|
|
Related Commands
chmod - Change existing file permissions
chown - Change file ownership
ls -l - View current file permissions
stat - Display detailed file information
Tips & Troubleshooting
- umask is subtractive: Higher values = more restrictive
- Applies to new files only: Existing files unchanged
- Shell-specific: Each shell session has its own umask
- Script considerations: Set umask early in scripts for consistency
- Common values: 022 (standard), 002 (group-friendly), 077 (paranoid)
- Testing: Create test files after changing umask to verify results