Table of contents
Suppose you created a file and directory in Linux and if you want to make it accessible to others how would you assign permissions to that file so that he/she can access it ??
Here come the File Permissions, by giving file permissions you can make a file or directory accessible to others. Every user has the responsibility of controlling access to their files.
There are three types of permissions:-
1) r - read permission
2) w - write permission
3) x - executable permission
Each permission (rwx) can be controlled at three levels.
1) u - user level i.e yourself
2) g - group level i.e can be controlled by 2-3 people who are working on the same project.
3) o - others i.e everyone on the system
To see the permissions of all files and directories that are located on your Linux machine execute :
$ ls -l
By executing this it will look like this :
In this image, you are seeing (drwx------) these are the permissions that are assigned at the user level. In this part you are seeing "d" i.e called directory and "x" means executable means that you can go into that directory if executable permissions have been assigned and if "x" is not assigned to that directory then you can't go into that directory.
So, let's break this part:
rwx : Read, write, execute is assigned at the user level.
--- : These 3 are blanks who are assigned at the group level.
--- : These 3 are blanks who are assigned at the others level.
OK !!! Now you had learned about File Permissions of Linux but how to change all these permissions, what is the command to change these permissions ??
"chmod" = change the file mode bits is the command to change all the permissions.
NOTE: The file is executable when it has script otherwise it will not show (x).
Now, I want to add and remove permissions at the three levels. Let's take a look at an example
REMOVING THE PERMISSIONS :
For removing the permissions we use (-) this subtracts the sign that you want to remove from the levels.
1) Suppose I want to remove the write permission from the group level.
$ chmod g-w <Name of directory>
g-w means we are removing the write permissions from the group level.
2) To remove all permissions i.e (read, write, execute)
$ chmod a-r <Name of directory>
a-r, "a" means all, and "r" means removing all permissions from the directory.
3) To remove write permissions from the user.
$ chmod u-w <Name of directory>
Here, "u" means user, and, "w" means write permissions.
ADDING THE PERMISSIONS :
For adding the permissions we use the (+) add sign that you want to assign the permissions in levels.
Let's take a look at the above examples:
1) Suppose I want to add write permission from the group level.
$ chmod g+w <Name of directory>
2) I want to give all the permissions i.e read, write, and execute at the user level.
$ chmod u+rwx <Name of directory>
So, that's the end of the topic on How to assign File Permissions in Linux.
I hope I added some knowledge to your learning part. If you"all love this blog please share it with other folks also and follow me Amit Maurya. You can follow me on twitter too.
THANK YOU :)