Skip to content

chmod command on Linux (change permissions)

The chmod command on Linux is used to change file and directory permissions.

It accepts the following permissions as a parameter:

  • Octets: representing the three classes: 777, 750, 640, etc.
  • Letters: The letters u for the owner user, g for the group and o for others to represent the classes, followed by symbols of addition (+), subtraction (-) and equality (=) for operations, and the letters r, w, x, X, s, and t.

The scheme for configuring permissions by octets is simpler, since only three numbers are used to configure permissions.

To use letters to configure permissions, see the Letters Table to Represent the Classes:

**Letter** **Description**
u File Owner (User)
g Group
o Others
All
You must use an operator, to add, subtract, or equality to configure the exact permissions:
**Symbol** **Description**
+ Add one permission without changing the others
- Subtract one permission without changing the others
= Configure the Exact permissions
Finally, the permissions can be represented by the letters you already know (rwx), adding **X**, **s**, and **t**:
( Set the execution bit to bit (x)
**Permission** **Description**
r Read
Write)
x Execute
other classes for files that already have the
SUID or SGID
t Sticky
s
The chmod command can be used with the following options:
  • -v: Reports file permissions, including changed permissions;
  • -c: Reports only the permissions that have changed;
  • -R: Change the permissions of all files and directories recursively within the same hierarchy.

Examples of changing permissions:

$ chmod 755 Leiame.txt

Change the permissions of the Leiame.txt file to rwx (7) for the User, r-x (5) for the Group, and r-x (5) for Others.

The same permission could be configured as:

$ chmod u=rwx, go=rex Leiame.txt

In this example, the symbol = was used to equate the permissions with the letters indicated.

To place execution permissions on a file, you can simply add execution permission. Since no class was entered, it will add execution permissions for all classes:

$ chmod +x Backup.sh

If we want to add write permissions to the file group, we can add write permission:

$ chmod g+w arquivo.txt

In this way, the group to which this file belongs is now allowed to write to it.

It is possible to change more than one permission at the same time, simply enter the permission letters (rw):

$ chmod o+rw accounting

It is also possible to change permissions at once for several classes. In this example, write and execute permissions are taken from all classes:

$ chmod ugo-wx read-only file

Be aware of the permissions that use the add (+) and subtract (-) operators, as they add or subtract permissions, changing the permissions that already exist for the file. The equality operator (=), on the other hand, sets the permissions exactly as indicated.

For ordinary users, chmod only allows the owner of the file or directory to change their permissions. Root, on the other hand, can change the permissions of any file or directory.

You must be very careful when changing file and directory permissions, as misconfigured permissions are a big deal for malware and intruders.

Are you an IT professional, support professional, or developer, have you ever considered learning Linux for real?

Is it still bad to get an LPI Linux Essentials certification from breaking?

And even better, with the best online course for Linux?

[RICH_REVIEWS_SHOW CATEGORY=“Course” num=“all “]

Do like these people and create your account now.

Here you have everything you need to succeed in the LPI and CompTIA exams

  • Practical Classes at Shell
  • Flashcards for memorization
  • Crossword Games
  • 06 virtual servers on Amazon just for you
  • Mind Maps
  • Video Glossary
  • Preparatory simulation for the exams
  • Personalized class schedule
  • Guided exercises — Real Laboratories
  • Lesson Resources (notes and others)

Do you want to know if a certification is worthwhile? Learn why salaries are good, and why companies are looking for Linux professionals.

You’ll understand that the benefits far outweigh the sacrifice.

And if you’ve made up your mind, check out our Certification Guide.

And if you want to know where to take the tests, check the list of cities.

If you want to know the language of the exams, check out this post.

Learn much more about Linux in our online course. You can register here. If you already have an account, you can log in here.