chmod

Change who may read, write or run a file

What it does

Every file has three sets of permissions: for the owner (u), the group (g) and everyone else (o). The permissions are read (r), write (w) and execute (x); for a folder, x means the right to enter it. ls -l shows them: -rwxr-xr-x reads in groups of three.

You set permissions with letters (+x, g+w, o-r) or with a three-digit number for the owner, the group and everyone else, where read = 4, write = 2 and execute = 1. So 644 is a regular file, 755 a script or a folder, 600 the owner only. -R changes a folder and everything inside.

Careful. chmod -R 777 lets everyone read, write and run everything, which is how security holes appear. SSH, by the way, refuses a key that anyone but its owner can read.

Syntax

chmod +x <file>
chmod <mode> <file>
chmod -R <mode> <folder>

Examples

Related commands

Practise · All commands