This page explains how to view, modify, and manage file permissions using chmod, chown, and umask.
Each file/directory has three sets of permissions:
[owner] [group] [others]
r = read
w = write
x = execute
Example:
-rwxr-xr-- 1 user group 1234 Jan 1 file.txt
| Section | Permissions |
|---|---|
| Owner | rwx |
| Group | r-x |
| Others | r-- |
chmod — Change File PermissionsSyntax:
chmod [options] mode file
chmod 755 script.sh
7 = rwx (read/write/execute)5 = r-x5 = r-x| Digit | Permission |
|---|---|
| 7 | rwx |
| 6 | rw- |
| 5 | r-x |
| 4 | r-- |
| 3 | -wx |
| 2 | -w- |
| 1 | --x |
| 0 | --- |
chmod u+x file.sh # Add execute to user
chmod g-w file.txt # Remove write from group
chmod o=r file.log # Set others to read-only
chown — Change File OwnershipSyntax:
chown [options] user[:group] file
Examples:
chown root file.txt # Change owner to root
chown user:staff report.docx # Change owner and group
chown -R user:group dir/ # Recursively change ownership
umask — Default Permission MaskDefines default permission subtracted from maximum possible (777 for dirs, 666 for files).
View current value:
umask
Common examples:
umask 022 # Default: 755 for dirs, 644 for files
umask 077 # Default: 700 for dirs, 600 for files
| umask | File Perm | Dir Perm |
|---|---|---|
| 022 | 644 | 755 |
| 027 | 640 | 750 |
| 077 | 600 | 700 |
| Command | Purpose | Example |
|---|---|---|
chmod |
Change permissions | chmod 755 file.sh |
chown |
Change ownership | chown user:group file.txt |
umask |
Set default permission mask | umask 022 |
ls -l to view current permissions.chown and chmod when creating secure scripts or directories.# Example: Secure private key
chmod 600 id_rsa
chown user:user id_rsa