UNDERSTANDING LINUX PERMISSIONS: A BASIC GUIDE

Linux is a powerful and versatile multi-user operating system that is widely used by multiple businesses and individuals around the world. One of the key features of Linux is its advanced file permission system, which provides users with a high degree of control over how files are accessed, modified, and shared.

UNDERSTANDING LINUX FILE PERMISSIONS

File permissions are an integral part of the Linux system security model. They specify who can do what with a file or directories on a system and how. Linux file permissions are based on three distinct types of permissions: read, write, and execute. In other words, these Linux permissions are a set of attributes that determine who can access a file or directory, and what they can do with it.

TYPES OF LINUX FILE PERMISSIONS

The Linux file permissions are designed to provide security by preventing unauthorized access to sensitive files and directories. There are three types of permissions and each of these is represented by a single letter, as follows:

Read (r): This permission allows a user or group to view the contents of a file or list the contents of a directory. It is represented by the letter r in permission settings.

Write (w): The write permission empowers users or groups to modify the contents of a file or create and delete files within a directory. It is symbolized by the letter w.

Execute (x): Execute permission, represented by the letter x, grants the ability to run scripts or execute.

The Three Permission Levels:

User: The owner is the one who created the user file and has the ability to modify or delete the file. By default, the owner is the user who created the file type.

Group: A group is a collection of users who have been granted access to a set of files or directories. The group permission is assigned to all members of the group.

Others: The other kinds of file permissions are assigned to all users who are not the owner or members of the group.

Numeric and Symbolic Permission Representation

Linux permissions can be represented in two formats: numeric and symbolic notation.

Numeric Notation:In this format, each permission is assigned a numeric value. Read is represented by 4, write by 2, and execute by 1. These values are then summed to create a three-digit number, where the first digit represents user permissions, the second digit represents group permissions, and the third digit represents others. For example, a file with permissions of 644 would mean that the user has read and write access (4+2=6), while the group and others have only read access (4).

Permission   Numeric Value
Read                           4
Write                           2
Execute                       1

Symbolic Notation: Symbolic notation employs a combination of letters and symbols to represent permissions. r signifies read, w represents write, x means execute and ‘-’ meaning no permissions. These symbols are used with user, group, and others to set permissions. For instance, rw-r–r– translates to user=read+write, group=read, others=read.

Symbol                  Meaning
   r                      Read permissions
   w                     Write permissions
   x                      Execute permissions
   –                      No permissions

MANAGING FILE PERMISSIONS IN LINUX

Managing file permissions in Linux is an important part of maintaining system security and controlling access to files and directories. There are several tools and techniques you can use to manage file permissions in Linux, including the following:

chmod: You can use chmod to grant or revoke read, write, and execute permissions for the owner, group, and others. The syntax for using chmod is-
chmod [permissions] [file or directory]

chown: You can use chown to transfer ownership of a file or directory to another user or group. The syntax for using chown is-
chown [user]:[group] [file or directory]

chgrp: You can use chgrp to assign a file or directory to a different group. The syntax for using chgrp is-
chgrp [group] [file or directory]

How to Check File Ownership Using the ls -l Command 

The ls command lists files and directories in a directory. When used with the -l option, it provides a detailed listing that includes ownership information. Here is how you can use it to check file ownership: 

ls -l

The output of this command will display information in a format like the following: 

-rw-r–r–  user1 group1 1234 sep 6 10:00 file.txt

Here is a breakdown of what each column represents: 

-rw-r–r–: These characters represent the file’s permissions. The first character indicates the file type (in this case, a regular file), followed by three sets of permissions for the file owner, group owner, and others. 

user1: This is the name of the file owner. 

group1: This is the name of the group owner. 

1234: This is the file size in bytes. 

Sep  6 10:00: This is the date and time of the last modification. 

file.txt: This is the file or directory name. 

In the example above, user1 owns the file file.txt, and it is part of the group group1. The file’s permissions are rw-r–r–, which means that the owner has read and write permissions, but others can only read the file. 

HOW TO CHANGE PERMISSIONS OF FILE IN LINUX?

Absolute Mode:
Example- chmod 640 file.txt
In this command, the first digit (6) represents the owner permission, which is read and write (4 + 2 = 6). The second digit (4) represents the permissions for the group, which is read-only (4 + 0 = 4). The third digit (0) represents the permissions on files, which is no permission (0 + 0 + 0 = 0).

Symbolic Mode:
Example- chmod u+x,g+x,o-rwx file.txt
n this command, “u” represents the owner, “g” represents the group, and “o” represents others. The “+x” adds execute permission for the owner and group, and “-rwx” removes all permissions for others.

RECURSIVE MODE

The recursive mode can also be used for the chmod command to change the permissions of a directory and all of its contents. To do this, use the “-R” option with the chmod command.

For example, to set read and write permissions for the owner, read-only permission for the group, and no permission for others for all files and directories in the “mydir” directory, you would use the following command:

Basic syntax: chmod -R 640 mydir

This command sets the permissions for all files and directories in “mydir” recursively.

CONCLUSION

Linux file permissions are an essential aspect of the operating system that allows you to control access to files and directories. The chmod command is used to change file permissions in Linux, and you can use either absolute mode or symbolic mode to do so. Also, the chmod command can be used in recursive mode to modify the permissions of a directory and all of its contents. Understanding file permissions, how to give permission to folder in Linux, and how to change them is crucial for managing files and directories in Linux.