File Permission
Using this file permission pcncept, you can do certain tasks:-
a)chomd: Change the permission of the file
Eg: Create a file with any name and type ls -l then you will see this permission
drwxr-x---
Here r will be considered as "Read", w as "Write" and x as "Execute".
I'll explain this example, what it defines.
d -> stands for directory
rwx -> userr-x -> group
And the last part is the other user
Eg: -rw-rw-r-- 1 ubuntu ubuntu 43 Sep 6 07:45 testing.txt
In this example, - stands for file
rw- : which means user can only read and write a file
rw-: which means group can only read and write a file.
r--: which means other user can only have read permission for that file.
Now I want to give Read permission to user, Write and Execute permission to the group and no permission to other user
ubuntu@ip-172-31-25-118:~$ sudo chmod 430 testing.txt
Output: -r---wx--- 1 ubuntu ubuntu 43 Sep 6 07:45 testing.txt
b)chown: Change the ownership or a user permission of the file
Consider this directory has a owner 'ubuntu'
drwxrwxr-x 4 ubuntu ubuntu 4096 Sep 6 07:14 A
To change the owner you can use below syntax
chown <new-owner-name> <filename/directoryname>
ubuntu@ip-172-31-25-118:~$ sudo chown daya A
Output: drwxrwxr-x 4 daya ubuntu 4096 Sep 6 07:14 A
c)chgrp: Change the group permission of the file.
Consider there is a group called devops which contains the user's like daya and jethalal
Eg devops:x:1002:daya,jethalal
drwxrwxr-x 4 daya ubuntu 4096 Sep 6 07:14 A
I want devops group need to access the directory 'A' instead of ubuntu group
Syntax: chgrp <new-group-name> <filename/directoryname>
Eg: ubuntu@ip-172-31-25-118:~$ sudo chgrp devops A
drwxrwxr-x 4 daya devops 4096 Sep 6 07:14 A
It means that user's like daya and jethalal can able to access the 'A' directory because we have given an access to a group called 'devops'.
Subscribe to my newsletter
Read articles from Bilal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by