Skip to main content

Command Palette

Search for a command to run...

📚Linux File System and Permissions

Updated
4 min read
📚Linux File System and Permissions
A

High functional, goal-oriented, and result driven Analyst with 2+ years of progressive experience. contributing to organizational success through high-level strategy and the implementation of excellence. Strong track record of inspiring effective cross-functional collaboration and innovative problem solving skills.

Passionate about exploring the ever-evolving world of DevOps technology. On a journey to unlock the secrets of seamless development, continuous integration, and deployment.

Committed to continuous improvement and lifelong learning.

🧾️Introduction

To properly manage files and directories, set permissions, and configure storage devices, one must have a solid understanding of the Linux file system. It's a vital part of developing and managing Linux systems. With this Linux feature, files gain an additional layer of security and can only be read, written to, or executed by users who have the appropriate permissions.

🌴Files Hierarchy in Linux

Linux is a single-rooted inverted tree structure(as shown below). Everything in Linux is a file or directory.

  • The root directory is denoted by /(slash), All other directories and files are organized beneath the root directory.

  • The /home directory a crucial part of Linux, gives individual users their own workspaces, protects sensitive information, and upholds security and privacy. On Linux systems, it is crucial for user management and system administration.

  • The core config files are stored in /etc, which controls the behavior of an OS.

  • Log files are generated in /var.

  • Any tool installation goes in /bin.

  • When we start the system it takes files from /boot.

🔐File Permissions

In Linux, each file and directory has rights that determine who can read, write, and execute it. These are called permissions. Permissions are expressed by a combination of letters and symbols for eg, -rwxr-xr-x, and can be established for the owner, group, and others.

Each user has full access to their home directory (/) by default. Depending on the permissions set by the owner, other users may have restricted or no access to another user's home directory.

Permission can be represented in two ways in Linux, as shown below:

The owner of the file is covered by the first set of permissions(from right). The user group that owns the file is subject to the second set of permissions. It is customary to refer to the third set of permissions as "others." Every Linux file has a group and an owner.

  • Read (r): When you want to give permission to view the contents of a file or list the contents of a directory.

  • Write (w): Allows modifying the contents of a file or creating, deleting, and renaming files in a directory.

  • Execute (x): Executing a file as a program or accessing (entering) a directory. You cannot run or execute a program in a Unix-like system unless the execute permission is set. However, such permission is not available in Windows.

Octal (base-8) representations of permissions, such as 755 or 644, are also possible. Each digit represents a category of permissions (owner, group, others), and each represents a combination of the permissions to read (4), write (2), and execute (1). For instance, code 755 indicates that the owner should read (4), write (2), and execute (1) whereas the group and others should read (4) and execute (1).

Most people have found it difficult to remember or write the correct Octal file permissions. This has been made easy in this blog by denoting each permission via 20..2. You need to denote each place of permission via 20..2 as shown below and add all the permissions.

📩Changing File Permissions: chmod

We can change the file permissions for a particular user, group, or other. We can add or remove the permissions. This can be achieved with the help of the "chmod" command in Linux which is an abbreviation of "change mode". This is also one of the ways to implement the security feature of Linux.

chmod [options] [mode] [File_name]

If you write ls -l, then it'll display all the details of files and their permissions as shown below:

If you would like to know the details of only any particular file and not all the files present in the directory then you can execute ls -l [file name]

In chmod, we can use relative permissions i.e. symbolic presentation (e.g., chmod u+x file.txt), or absolute permissions i.e. octal presentation(e.g., chmod 755 file.txt) to set permissions.

  • Relative Permissions: To define or alter permissions, we use a combination of letters and operators, which is the most commonly used way. ('+': add permissions. For example, chmod +x file.txt adds execute permission to the file.

    '-': remove permissions. For example, chmod -w file.txt removes write permission from the file.

  • Absolute permissions: Octal permissions are frequently used to indicate absolute file permissions. It consists of three digits, such as 755 or 644, where each digit stands for one of the three categories of rights: user, group, and others.

📎Conclusions

In Linux, file permissions are frequently used to set up access to files and directories. They play a key role in Linux's security feature by allowing for precise control over who can access, edit, and execute files.

It is essential to achieve a balance between security and usability when handling file permissions in Linux. To ensure the integrity and confidentiality of your files and data, provide only the permissions that are required for users and groups. Audit and review permissions on a regular basis to ensure they comply with your system's security regulations.

More from this blog

Alkama DevOps Journey

8 posts