LinuxCommandLibrary

chmod

change file access permissions

TLDR

Make file executable

$ chmod +x [script.sh]
copy
Set specific permissions
$ chmod 755 [file]
copy
Remove write permission
$ chmod -w [file]
copy
Recursive change
$ chmod -R 755 [directory/]
copy
Set permissions symbolically
$ chmod u=rwx,g=rx,o=r [file]
copy

SYNOPSIS

chmod [options] mode file...

DESCRIPTION

chmod (change mode) modifies file access permissions. It controls read, write, and execute permissions for three classes of users: the file owner (user), the file's group, and all other users.
Permissions can be specified in two ways: numeric (octal) mode using digits 0-7, or symbolic mode using letters (u/g/o/a, +/-/=, r/w/x). Numeric mode sets all permissions at once, while symbolic mode allows adding or removing individual permissions. The command is fundamental to Unix file security and access control.

PARAMETERS

-R, --recursive

Change files and directories recursively
-v, --verbose
Verbose output
-c, --changes
Report only changes
--reference=file
Use permissions from reference file

NUMERIC MODE

Octal digits (0-7):
- 4 - Read (r)
- 2 - Write (w)
- 1 - Execute (x)
Common modes:
- 755 - rwxr-xr-x (owner full, others read/execute)
- 644 - rw-r--r-- (owner read/write, others read)
- 600 - rw------- (owner only)
- 777 - rwxrwxrwx (all permissions, usually bad idea)

SYMBOLIC MODE

Format: [ugoa][+-=][rwxXst]
Who:
- u - User (owner)
- g - Group
- o - Others
- a - All
Operation:
- + - Add permission
- - - Remove permission
- = - Set exact permission
Permissions:
- r - Read
- w - Write
- x - Execute
- X - Execute only if directory
- s - Setuid/setgid
- t - Sticky bit

WORKFLOW

$ # Make script executable
chmod +x script.sh

# Set standard file permissions
chmod 644 file.txt

# Set directory permissions
chmod 755 directory/

# Recursive change
chmod -R 755 public_html/

# Remove write for group and others
chmod go-w file.txt

# Add execute for all
chmod a+x program

# Set exact permissions
chmod u=rwx,g=rx,o= private_script
copy

SPECIAL MODES

Setuid (4000):

Run as file owner
Setgid (2000):
Run as file group or inherit directory group
Sticky (1000):
Only owner can delete (common for /tmp)
Example: `chmod 4755 program` (setuid + rwxr-xr-x)

CAVEATS

Requires ownership or root privileges. 777 permissions are security risk. Recursive changes can break systems. Symbolic links not affected (use chmod -h on some systems). Execute on files vs directories different meaning.

HISTORY

chmod has been part of Unix since the early 1970s, implementing the Unix permission model designed by Dennis Ritchie and Ken Thompson.

SEE ALSO

chown(1), chgrp(1), umask(1), ls(1)

> TERMINAL_GEAR

Curated for the Linux community

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

$54.00
Raspberry Pi 5 8GB

Raspberry Pi 5 8GB

$134.50
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

$739.99
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00