chmod command in Linux

Ali Zhagparov
Javarevisited
Published in
3 min readJul 19, 2021

Use chmod Command to get directories access, set files permission, or just control the user capabilities. This guide is made to help you with script management and running.

About chmod Command

This command has the typical Linux syntax: a command, then the options, and the file or folder at the end, which have to be applied with the command itself:

chmod [reference][operator][mode] file...

For a start, let’s take a look at the existing Linux access rights and how to set them. There are three main types of rights:

r - reading;
w - writing;
x - execution.

Also, there are three categories of users for whom you can set these permissions on a Linux file:

Reference   Class     Description
u owner file's owner
g group users who are members of
the file's group
o others users who are neither the
file's owner nor members of
the file's group
a all All three of the above, same as ugo

To see file permissions use

$ ls -l file

Where

A dash(-) means that is the regular file

d means it’s a directory

The syntax for setting rights is: user_group / action / type_of_rightSigns, such as “+” and “-“, are used as actions. Consider the examples:

  • u+rx — to enable the execution for the owner;
  • ugo+rx — to allow the execution and reading for everyone;
  • ug+w — to enable writing for group and owner;
  • ugo+rwx — to allow everything for everyone.

But there is also another way to write the access rights down:

  • 0 — no rights;
  • 1 — execution only;
  • 2 — writing only;
  • 3 — execution and recording;
  • 4 — reading only;
  • 5 — reading and execution;
  • 6 — reading and writing;
  • 7 — reading, writing, and execution.

The access rights for Linux and for file are the same. Setting them, specify the number of rights for the owner, then for the group, and then for the rest. Examples:

000 — to restrict writing, reading, and executing for everyone;

744 — to allow everything for the owner, reading only for the rest;

755 — to allow everything for the owner, reading and execution-only for the rest;

777 — to allow everything for everyone:

--

--