Changing Permissions: chmod

chmod sets file permissions using either symbolic letters or numeric codes.

Syntaxchmod MODE file # e.g. chmod 755 file or chmod u+x file

chmod changes who can do what with a file. There are two ways to express the new permissions.

Symbolic mode

Combine who (user, group, other, all) with + / - and a permission letter.

  • chmod u+x file β€” give the owner execute.
  • chmod go-w file β€” remove write from group and other.

Numeric (octal) mode

Each permission has a value: read = 4, write = 2, execute = 1. Add them per group to get one digit each for owner, group and other.

  • 755 = rwx r-x r-x (common for programs and folders).
  • 644 = rw- r-- r-- (common for regular files).

Example

Example Β· bash
# Make a script executable
chmod +x deploy.sh

# Numeric: owner rwx, group & other r-x
chmod 755 deploy.sh

# A private file only the owner can read/write
chmod 600 secret.key

# Apply to a folder and everything inside it
chmod -R 644 website/

When to use it

  • A developer runs 'chmod +x deploy.sh' to make a shell script executable before running it.
  • A sysadmin sets 'chmod 600 ~/.ssh/id_rsa' to restrict a private key to owner-only access, satisfying SSH security requirements.
  • A web server admin uses 'chmod -R 755 /var/www/html' to ensure the web root is readable by the web server process.

More examples

Add execute permission symbolically

Uses symbolic mode (u+x, +x) to add execute permission to a script without affecting other bits.

Example Β· bash
# Add execute for owner only
chmod u+x script.sh

# Add execute for everyone
chmod +x script.sh

ls -l script.sh
# -rwxr-xr-x 1 alice alice 256 Jul 16 script.sh

Set permissions with octal

Sets permissions using octal notation where each digit sums r(4)+w(2)+x(1) for owner, group, and others.

Example Β· bash
# 600: owner rw, group none, others none
chmod 600 ~/.ssh/id_rsa

# 755: owner rwx, group r-x, others r-x
chmod 755 /usr/local/bin/mytool

# 644: owner rw, group r, others r
chmod 644 /etc/app/config.ini

Recursive permission change

Uses find+chmod for fine-grained recursive changes, applying different modes to files vs directories.

Example Β· bash
# Set all directories to 755 and files to 644
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

# Or use chmod -R (applies same mode to everything)
chmod -R 750 /opt/myapp/

Discussion

  • Be the first to comment on this lesson.
Changing Permissions: chmod β€” Linux | SoundsCode