Linux File Permissions - Basics and Commands
As an open source, accessing a file requires more security in Linux.
This has been maintained by providing file permissions and access modes.
These are applicable for all files and directory.
File Permissions:
The file permissions tells who all have access to the files.There are 3 attributes in file permissions classified as,
The owner permission defines the action that can be done to the files by the Owner.
Group Permission:
The Group permission defines the action that can be done to the files by the users on the group.
Other or world Permission:
The Other permissions defines the action that can be done to the files by the world or public.
File Modes:
The file modes defines what kind of access are provided to the users. There are 3 attributes in file modes as well,
The above image shows the file permissions for files.
File Permissions:
The file permissions tells who all have access to the files.There are 3 attributes in file permissions classified as,
- Owner Permission
- Group Permission
- Other or world Permission
The owner permission defines the action that can be done to the files by the Owner.
Group Permission:
The Group permission defines the action that can be done to the files by the users on the group.
Other or world Permission:
The Other permissions defines the action that can be done to the files by the world or public.
File Modes:
The file modes defines what kind of access are provided to the users. There are 3 attributes in file modes as well,
- read
- write
- execute
read - The read mode allows to view the file( Readable ). The value for read access is 4
write - The write mode allows to modify the file ( Readable, Writable and Removable ). The value for write access is 2
execute - The execution mode allows to run the file as a program( Mostly applied to bash files in Linux ). The value for execute access is 1
write - The write mode allows to modify the file ( Readable, Writable and Removable ). The value for write access is 2
execute - The execution mode allows to run the file as a program( Mostly applied to bash files in Linux ). The value for execute access is 1
The above image shows the file permissions for files.
- First will be the type of file. It may be a file, directory, or a link.
- Second three sets of value is assigned to the Owner of the file
- The third three sets is assigned to the Group.
- The final three sets is assigned to the public or world.
Printing the File permissions:
To view file permissions and modes we can use either ls command with -l flag or ll command.
The file permission for a directory is always started with d.
The file permission for a file is always started with d.
The file permission for a link is always started with l.
Changing the Ownership of a file:
The Owner ship of the file can be changed in order to provide access to other users and groups. To obtain this we use chown command.
Using chown command we can change the owner of the file at a time or user and group at the same time.
Changing the group of a file:
If you want to change the group-owner alone, you can use chgrp command
If you wish to change the permissions to all the subdirectories use -R flag along the chown command. It will recursively change the permissions for all files inside the directory
Changing File modes:
As mentioned earlier the file modes defines the kind of access are provided to the users or groups to the file either the user has the right to read or write or delete.
When comes to file mode there are two ways to change it.
We will see the changing the file mode through absolute mode. On the following example we will provide 761 permission for a file.
For the test1.txt file the permissions are as follows,
Owner - File Owner jhony can read,write and execute the file.
Group - Users under the group ljunix can read and write the file.
Others - Rest of the users cannot access the file.
Symbolic mode:
The symbolic mode allows us to modify permissions for a specific owner. It uses mathematical operators to modify the file permissions.
In Symbolic mode we use some user denotations to change the permission along with the operators.
u stands for Owner
g stands for Group
o stands for Others
a stands for all
For Operators the permissions will be,
We will see this with an example, initially we will set the permissions to null for our test file
Now we will apply using symbolic mode,
Without defining a user denotations the permissions will set to all the owner.
We will add read and write access to the Owner of the file,
These are the methods followed in changing the permissions for files using absolute mode and symbolic mode.
Hope this articles helps you. Feel free to ask if you have any questions.
To view file permissions and modes we can use either ls command with -l flag or ll command.
The file permission for a directory is always started with d.
The file permission for a file is always started with d.
The file permission for a link is always started with l.
Changing the Ownership of a file:
The Owner ship of the file can be changed in order to provide access to other users and groups. To obtain this we use chown command.
Using chown command we can change the owner of the file at a time or user and group at the same time.
Changing the group of a file:
If you want to change the group-owner alone, you can use chgrp command
If you wish to change the permissions to all the subdirectories use -R flag along the chown command. It will recursively change the permissions for all files inside the directory
Changing File modes:
As mentioned earlier the file modes defines the kind of access are provided to the users or groups to the file either the user has the right to read or write or delete.
When comes to file mode there are two ways to change it.
- Absolute mode
- Symbolic mode
Absolute Mode:
Absolute mode is also known as Numeric mode, file permissions are not represented as characters but a three-digit octal number. r=4, w=2 and x=1. Let us view how the values are defined on the following table.
We will see the changing the file mode through absolute mode. On the following example we will provide 761 permission for a file.
For the test1.txt file the permissions are as follows,
Owner - File Owner jhony can read,write and execute the file.
Group - Users under the group ljunix can read and write the file.
Others - Rest of the users cannot access the file.
Symbolic mode:
The symbolic mode allows us to modify permissions for a specific owner. It uses mathematical operators to modify the file permissions.
In Symbolic mode we use some user denotations to change the permission along with the operators.
u stands for Owner
g stands for Group
o stands for Others
a stands for all
For Operators the permissions will be,
We will see this with an example, initially we will set the permissions to null for our test file
Now we will apply using symbolic mode,
Without defining a user denotations the permissions will set to all the owner.
We will add read and write access to the Owner of the file,
These are the methods followed in changing the permissions for files using absolute mode and symbolic mode.
Hope this articles helps you. Feel free to ask if you have any questions.
Comments