Permissions, users and access

Command chmod

Change file permissions

Linux · Bash examples · commands run on the selected server

When to use chmod

Use chmod to adjust permission bits deliberately for files and directories. A directory's execute bit allows traversal, while a regular file's execute bit permits execution; the same numeric mode can therefore have very different effects.

Syntax

chmod [OPTIONS] MODE FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

u+x
Add execution permissions to the owner.
640
Read and write to the owner, read to the group, no permissions for others.
-R
Recursively apply the mode.

Usage examples

Allow script to run

chmod u+x ./deploy.sh

Only the owner's execute bit is added; the other permission bits remain as before.

Restrict access to a file

chmod 640 ./app.conf

The owner can read and write, the group can read, and other users receive no access through these mode bits.

Allow entry into a private directory

chmod 700 ./private

Only the owner can list, traverse and modify this private directory through its basic mode bits.

Notes and limitations

  • For directories, execute (x) permission allows traversal. Files and directories often need different modes.
  • Do not use 777 as a universal fix. Check which files and directories -R will affect.

Common questions and troubleshooting

Why is chmod 777 a poor permission fix?

It grants every local user broad access and may expose secrets or writable code. Identify the required user, group and operation instead.

Why can access still fail after changing mode bits?

A parent directory, ACL, read-only mount or security policy can block access. Inspect the full path and effective account before broadening permissions.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man chmod.