Skip to content

chmod

17 commands

Changes file permissions using symbolic or octal modes, including setuid, setgid and sticky bits.

  • permissions
  • security

Install chmod

sudo apt install coreutils

Symbolic modes5

chmod +x <file>

Makes a file executable.

Link
chmod u+x <file>

Executable for the owner only.

Link
chmod go-rwx <file>

Removes all access for group and others.

Link
chmod a+r <file>

Readable by everyone.

Link
chmod u=rw,go=r <file>

Sets exact permissions per class.

Link

Octal modes4

chmod 644 <file>

rw-r--r--: owner reads and writes, everyone else reads. Typical for files.

Link
chmod 755 <dir>

rwxr-xr-x: typical for directories and scripts.

Link
chmod 600 <file>

rw-------: private keys must be this strict or SSH refuses them.

Link
chmod 700 <dir>

Only the owner can enter or list.

Link

Special bits4

chmod u+s <file>

Sets SUID: the program runs with its owner’s privileges. Dangerous on root-owned binaries.

Link
chmod g+s <dir>

SGID on a directory: new files inherit the directory’s group.

Link
chmod +t <dir>

Sticky bit: users can delete only their own files, as in /tmp.

Link
chmod 4755 <file>

Octal SUID plus 755. The leading digit is 4 for SUID, 2 for SGID and 1 for sticky.

Link

Recursive4

chmod -R <mode> <dir>

Applies a mode to a whole tree.

Link
find <dir> -type d -exec chmod 755 {} +

Sets directories and files differently — usually what you want instead of chmod -R.

Link
find <dir> -type f -exec chmod 644 {} +

Sets every file to 644.

Link
chmod --reference=<ref> <file>

Copies permissions from another file (GNU).

Link