top of page
Image by Blake Cheek
  • Writer's pictureBeri Contraster

File Permissions in Linux - Explained



Welcome Reader, Today I'll explain everything about file permissions in Linux. File permissions could cause serious problems if not set properly. Let's start with how to read permissions.


Permissions

fig.1

The above image shows how permissions are displayed in Linux environments. Please take a closer look at the image before moving on. Two utilities are used to set permissions in Linux.


  1. chown - used to change owners of the file.

  2. chmod - used to change permissions of the file.


Change Owner

Let's start with Chown. Let's say I created a file with the root user but I want to make 'Kali' (which is another user) the owner of the file.



In the above code snipped I changed the owner and group of the file from root to Kali. We can do the same with Directory by using the following command.



The above code snipped shows how to change directory owners. You can also use -R for recursive owner permissions. It'll change the owner of all the files in the directory.


Change Permissions

Chmod is used to change file permissions. Let's say I want to allow the owner of the file to read, write, and execute. I want the group to just read and execute and all the other users can execute only.



Let's break it down. Read has a value of 4, write has a value of 2, and execute has a value of 1 as shown in the fig.1 above. Now If want to allow someone to read, write, and execute which are 4 (for read), (2 for write), and 1 (for execute). So 4+2+1 will be 7. If I want someone to read and execute I will use 6 (4 -> read & 2 -> write).


The first number 7 in the above code snipped set owner permissions, 5 set permissions for the groups, and 1 set permissions for all the other users. We can use -R for recursive just like we used in the chown command.


Be carefull when managing permissions a tiny misconfiguration of permissions can cause seriouse problems.

Thanks for reading. If you have any questions please don't hesitate to ask me.

25 views0 comments

Recent Posts

See All

Comments


bottom of page