Linux Permissions

File Permissions in Linux / Unix: How to Read, Write & Change?

A multi-user operating system that allows for simultaneous access by a large number of users is known as UNIX. Linux is an exact replica of UNIX. In addition, Linux does not require any adaptations in order to run on mainframes and servers. However, this raises concerns about data security because an unauthorised user who has malicious intent could potentially corrupt, change, or delete essential data. Linux uses two distinct levels of authorization to achieve its goal of providing effective security.

Ownership \sPermission
You will learn the following Linux file commands by following this tutorial:

Linux File Ownership

If you are unable to view the video, please click here.
Ownership of the Linux File System
On your Unix or Linux system, each file and directory has one of the three types of owner that are described in the following sentence.

The user who created the file is the file’s owner. The person who initially created a file is the one who is considered to be the owner of that file. As a result, a user is also frequently referred to as an owner.

A user group may include participation from more than one user. Users who are members of the same group will all share the same level of access to the file in terms of the Linux group permissions. Imagine that you are working on a project that requires a number of people to have access to the same file. Instead of manually assigning permissions to each user, you could add all users to a group and then assign group permission to file in such a way that only members of this group and no one else can read or modify the files. This would eliminate the need to manually assign permissions to each user.

Any other user who is authorised to access a particular file. This individual is not the creator of the file, nor does he belong to a usergroup that has ownership rights to the file. In all likelihood, this refers to everyone else. As a result, the process of setting permissions for others is also sometimes referred to as setting permissions for the entire world.

Now, the most important question is how Linux differentiates between these three types of users, so that a user with the name “A” cannot change the contents of a file that another user with the name “B” uses to store important information or data. It is as if you do not want your coworker to view your images while they are working on your Linux computer. Here is where permissions come into play; these settings determine how users behave.

Let’s get a grasp on how Linux’s permission system works, shall we?

Linux File Permissions

The following three permissions are set for every file and directory in your UNIX/Linux system. These permissions are defined for each of the three owners that were discussed earlier.

Read: You have the permission to open a file and read its contents thanks to this permission. You are able to list the contents of a directory if you have read permission on that directory.
Write: If you have the write permission, you have the ability to change the information contained in a file. If a directory grants you the “write” permission, you will have the ability to add, delete, and rename the files that are stored in that directory. Take into consideration a situation in which you are required to have write permission on the file, but you do not have write permission on the directory in which the file is stored. You will have the ability to make changes to the contents of the file. However, you will be unable to change the file’s name, relocate it, or delete it from the directory.
Run: When using Windows, an executable programme will typically have the extension “.exe,” and it is very simple to run such a programme. In Unix and Linux, the execute permission must be enabled before a programme can be run successfully. If the execute permission is not set, you will not be able to run the programme, but you will still be able to view and modify the programme code (provided that read and write permissions are set).
File Permissions in Linux/Unix
File Permissions in Linux/Unix
Let’s take a look at some examples of file permissions in Linux:

ls – l on terminal gives

ls – l \sFile Permissions in Linux/Unix
Here, we have underlined “-rw-rw-r,” which is the code that provides information regarding the Unix permissions that have been granted to the owner, user group, and the world. This code appears to be quite strange, but it is the one that provides this information.

The initial dash (‘–’) indicates that we have chosen a file at this point.


File Permissions in Linux/Unix
On the other hand, if it were a directory, the letter d would have been displayed.

File Permissions in Linux/Unix
The cast of characters is not too difficult to keep in mind.

R stands for “read permission.”
w stands for “write permission,” x for “execute permission,” and “-” indicates “no permission.”

Let’s take a look at it from this angle.

The prefix “rw-” denotes the beginning of the code. This would imply that the owner of the property ‘Home’ can:

File Permissions in Linux/Unix
Examine the record.
Create or make changes to the file.
Due to the fact that the execute bit is set to the value ‘-‘, he is unable to run the file.
Many Linux distributions, such as Fedora, CentOS, Ubuntu, and others of its kind, are programmed to automatically add users to a group with the same group name as the user name. As a result, the user “tom” has been added to a group also called “tom.”

Changing file/directory permissions in Linux Using ‘chmod’ command

The following prefix, ‘rw-,’ comes next. It is for the user group known as “Home,” and members of that group can:

Examine the record.
Create or make changes to the file.
The third component is intended for everyone, which includes all users. It says ‘r–’. This means that the user is restricted to only:

Examine the record.
File Permissions in Linux/Unix
Changing the permissions on files and directories in Linux Making use of the ‘chmod’ command
Suppose you do not want your coworker to view the personal images you have uploaded. Changing the permissions on the files is one way to accomplish this.

The ‘chmod’ command, which stands for ‘change mode,’ is available for our use. We have the ability to set permissions (read, write, and execute) on a file or directory for the owner of the file or directory, the group the file or directory belongs to, and the world.


filename permissions set with chmod
The command can be executed in one of two ways:

Absolute mode
The mode of symbols

Absolute(Numeric) Mode in Linux

In this mode, file permissions are not represented as characters but a three-digit octal number.

The table below gives numbers for all for permissions types.

Number Permission Type Symbol
0 No Permission
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write +Execute rwx

Let’s see the chmod permissions command in action.

In the above-given terminal window, we have changed the permissions of the file ‘sample to ‘764’.

‘764’ absolute code says the following:

  • Owner can read, write and execute
  • Usergroup can read and write
  • World can only read

This is shown as ‘-rwxrw-r–

This is how you can change user permissions in Linux on file by assigning an absolute number.

Symbolic Mode in Linux

In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify permissions of a specific owner. It makes use of mathematical symbols to modify the Unix file permissions.

Operator Description
+ Adds a permission to a file or directory
Removes the permission
= Sets the permission and overrides the permissions set earlier.

The various owners are represented as –

User Denotations
u user/owner
g group
o other
a all