Skip to content

Changing File Permissions

What do File Permissions Do?

File permissions control the actions that users can perform and which users have access to files and directories

The chmod Command

The chmod command is the command that is actually used to change the permissions of a file or directory

Running the chmod command looks something like this

console
chmod [options] /path/to/file/or/dir

Changing Permissions Using Numbers

The read, write, and execute permissions are given their own numbers: the execute permission is 1, the write permission is 2, and the read permission and 4.

The sum of these numbers determines the permission combination.

This table contains numbers and their corresponding permissions.

Number Command
7 read, write, execute
6 read, write
5 read, execute
4 read
3 write, execute
2 write
1 execute
0 no permissions

The first digit of the chmod command corresponds to the permissions of the owner, the second for the group, and the third is for others.

An example of running the chmod command using digits would look something like this

console
chmod 735 /path/to/file/or/dir

What this command actually means is described below

  • Since the first digit is 7, the owner is given permissions: read, write, and execute.
  • The second digit being 3 means that the group is given the permissions: write, execute.
  • Finally, the third digit being 5 means that others are given permissions: read, execute.

Changing Permissions Using Letters

The read, write, and execute permissions are given the respective letters r, w, and x.

To specify who the permission is being assigned to, a u is used for the owner of the file, g for the group, and o for everyone else, and a for all users.

To assign permissions, a + operator is used. To remove permissions, a - operator is used. To set the permissions, an = operator is used.

To give no permissionms, a --- operator can be attached to whoever the permission is being assigned to.

Using this information, the command previously shown can be rewritten to this command

console
chmod u=rwx,g=wx,o=rx /path/to/file/or/dir

To give others no permissions, the following command can be ran

console
chmod o=--- /path/to/file/or/dir

To remove the write permission from the group, the following command can be ran

console
chmod g-w /path/to/file/or/dir

To add the execute permission to others, the following command can be ran

console
chmod o+x /path/to/file/or/dir