Most of the fresh users to Linux are searching for a way via the command prompt to modify the file/directory permissions. Those users would be pleased to know that there is a command – dubbed or chmod, e.g. change mode – that help you do this quickly. Chmod modifies each document’s rights by mode, in which the mode specifies the privileges to be updated. You may designate a mode with octal numerical or letters.

Understand the Mode Privileges

To understand the chmod, you have first to understand simple things regarding it. Open the command terminal and list all the directories or folders to check the privileges assigned to owners, groups, and others. You have to use the list command followed by the –og keyword. It will display the folder type, e.g. d belongs to a directory, r means to read, w means to write, and x means execution.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image7-3.png" data-lazy- height="202" src="data:image/svg xml,” width=”632″>

Navigate to the Desktop directory using the cd command and list the privileges assigned to any particular file using the ls command. In our case, the file is index.html. First ‘-‘ means this is not a directory. After that rw, this file has read and writes privileges assigned to the owner but no execution rights. Next rw- refers to assigned privileges to the group and last r– means privileges assigned to others for this particular file index.html.

$ cd Desktop

$ ls –lart filename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image9-3.png" data-lazy- height="68" src="data:image/svg xml,” width=”640″>

Numeric Mode

You have to simply understand that numeric mode includes numbers to assign privileges to owners, groups, and others. Number 4 is for reading, number 2 is for write, number 3 is for execution, and number 7 is for all, e.g. read, write, and execution privileges. Now navigate to the Desktop directory and create a new file named sample.txt. List all the files residing in the Desktop directory using the simple list command and display the newly created file.

$ cd Desktop

$ touch filename

$ ls

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image8-3.png" data-lazy- height="68" src="data:image/svg xml,” width=”637″>

Read Privileges

To assign read privileges only to the owner, you have to add number 4 in first place in the chmod command followed by the filename. When you execute the list command for this file, you will see that only read privileges have been assigned to an owner.

$ chmod 400 filenames

$ ls –lart filename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image11-1.png" data-lazy- height="51" src="data:image/svg xml,” width=”648″>

To give reading privileges to a group, add number 4 in second place. Read privileges have been assigned to a group.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image10-2.png" data-lazy- height="49" src="data:image/svg xml,” width=”644″>

To allocate read privileges to others, add number 4 in the third location. Read privileges have been assigned to a group.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image13-1.png" data-lazy- height="55" src="data:image/svg xml,” width=”630″>

To grant read privileges to the owner, group, and others at the same time, add number 4 at all locations.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image12-1.png" data-lazy- height="54" src="data:image/svg xml,” width=”642″>

Writing Privileges

To offer the write privileges to the owner, you will have to add number 2 in first place in the chmod command. When you execute the list command for this file, you will see that only writing privileges have been assigned to an owner.

$ chmod 200 filenames

$ ls –lart filename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image15-1.png" data-lazy- height="54" src="data:image/svg xml,” width=”641″>

To allocate writing privileges to the group, add number 2 in the second residence. Read privileges have been assigned to a group.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image14-1.png" data-lazy- height="51" src="data:image/svg xml,” width=”642″>

To assign writing privileges to others, add number 2 in third place. Read privileges have been assigned to a group.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image18.png" data-lazy- height="53" src="data:image/svg xml,” width=”631″>

To grant writing rights to the owner, group, and others at the same time, add number 2 at all places.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image16.png" data-lazy- height="50" src="data:image/svg xml,” width=”647″>

Execution Privileges

To grant the owner’s execution rights, you will have to add number 1 in the first place.

$ chmod 100 filenames

$ ls –lart filename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image17.png" data-lazy- height="50" src="data:image/svg xml,” width=”624″>

To allocate execution rights to the group, add number 1 in the second residence.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image19.png" data-lazy- height="53" src="data:image/svg xml,” width=”642″>

To assign execution rights to others, add number 1 in third place.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image20.png" data-lazy- height="50" src="data:image/svg xml,” width=”639″>

To grant execution rights to the owner, group, and others at the same time, add number 4 at all locations.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image21.png" data-lazy- height="53" src="data:image/svg xml,” width=”638″>

To grant all read, write, and execution rights to the owner, group, and others simultaneously, you have to add 7 on all the places.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image22.png" data-lazy- height="53" src="data:image/svg xml,” width=”642″>

Symbolic Mode

In this mode, you will be using symbols to give rights.

Use the x symbol to give everyone the execution rights.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image23.png" data-lazy- height="52" src="data:image/svg xml,” width=”646″>

To take back, the execution rights add the -x symbol.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image24.png" data-lazy- height="52" src="data:image/svg xml,” width=”643″>

To grant execution rights only to the current user, which is the owner, add the u x symbol.

Similarly, groups use g x, and others use o x.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image22-1.png" data-lazy- height="53" src="data:image/svg xml,” width=”642″>

Take back the execution rights from all, add the ugo-x symbol. You can use a-x instead of ugo-x.

$ chmod ugo-x filename

$ chmod a-x filename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image26.png" data-lazy- height="50" src="data:image/svg xml,” width=”641″>

If you want to copy group rights and assign them to the user, you can use the g=u symbol.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image1-4.png" data-lazy- height="51" src="data:image/svg xml,” width=”652″>

You can use the rights of one file as a reference for another file. For this, simply use the reference keyword followed by the names of files.

$ chmod –reference=filename1 filename2

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image2-4.png" data-lazy- height="69" src="data:image/svg xml,” width=”643″>

If you want to assign all rights to the owner, no writing privileges to the group, and don’t want to assign any rights to others, you can simply do that by a simple concept of Read=4, write=2, and execution=1. Assign 7 to the owner as 4 2 1=7. Assign 5 to the group as 4 0 1 and assign 0 to others.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image3-3.png" data-lazy- height="49" src="data:image/svg xml,” width=”645″>

To assign read permissions to all, add a r symbol.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image4-3.png" data-lazy- height="55" src="data:image/svg xml,” width=”649″>

To give read and write permissions to groups and others, add the go rw symbol.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image5-3.png" data-lazy- height="54" src="data:image/svg xml,” width=”648″>

If you want to give everybody privileges for reading, write, execute and setup Group-ID,  add the =rwx,g s symbol.

$ chmod =rwx,g s filename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image6-3.png" data-lazy- height="52" src="data:image/svg xml,” width=”656″>

Conclusion

We had to bring up the basic concepts of chmod instruction in this tutorial and provided examples demonstrating how it will be used in possible situations.

About the author

<img alt="Aqsa Yasin" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/Author-Image-150×150.jpg5ff5f913d0c99.jpg" height="112" src="data:image/svg xml,” width=”112″>

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.