Permissions in Linux:
Like in this world everything has a particular owner and everyone cannot use everything without proper permission, For security reason Linux also have different permissions, that do not allow other users or groups to access a particular file, make changes to it or execute it unless if proper permissions are assigned to them.
There are three types of permissions in Linux
- Read
- Write
- Execute
Read:
It means that a user can access a file
Write:
It means that a user can make changes in a file
Execute:
It means that a user can execute a file.
How to check permission for any file in Linux?
You can check the permissions of any file by using the following command.
ls -l FileName
For Example:
To check the permission of a file named myFile.sh we can write
ls -l myFile.sh
-rw-r–r– 1 kali kali 0 Jun 8 06:07 myfile.sh
- – means file
- d means Directory
- I mean link
- rwx owner
- rwx group
- rwx other users
r = 4
w = 2
x = 1
How to provide execute permission to all owners, groups, and all other users?
chmod +x fileName
What is meant by 644 permission in Linux?
644 = rw-r–r–
It means that the owner can read and write but cannot execute, the group and other users can only read the file.
r + w = rw
4 + 2 = 6
4 = r–
4 = r–
rw-r–r–
How to assign only read write and execute permission to the owner and only read permission to other users?
chmod 744 fileName
How to assign a write permission for the file to the owner.
For Example:
chmod u+w myfile.sh
How to assign only execute permission to the owner.
For example:
chmod u+x myfile.sh
How to assign read, write, and execute permission to all users to a particular file?
chmod 777 FileName
The above command will provide read, write, and execute permissions to all the users.
— means a user cannot read, write and execute a file
r– It means that a user only read a file
rw- It means that a user can only read and write a file
–x It means that a user can only execute a file.
r– Read Permission
r-x Read and execute
rw- Read and Write Permission
rwx Read, Write and Execute Permission (All Permission)
read(4) = 4
read(4) and Execute (1) = 5
read(4), Write(2) and Execute (1) = 7
What is mean by chmod -R 777 /
It means that all the files under root directory will have all the permissions like rwxrwxrwx.