DEV Community

Ugochi Ukaegbu
Ugochi Ukaegbu

Posted on • Originally published at dhebbydavid.hashnode.dev on

Linux Permissions: A Beginner's Guide

INTRODUCTION

By now, you should be aware that on Linux, everything is a file. Different permission levels are assigned to these files. Permission, according to the Cambridge Dictionary, is the act of permitting someone or something to happen.

As an illustration, the owner of a document in Google Docs can provide different access to all users or only specific users.

The owner can grant read-only permission, meaning that other users can view the document but not alter it. Other users may be permitted to join as editors with the owner's consent. By doing this, they can edit the file. With Linux, the same is true.

As the title suggests, this article is for beginners who are interested in knowing about Linux Permissions.

LINUX PERMISSIONS ON A PLATTER

gif

A key component of the operating system's security model in Linux is the concept of permissions. Linux permissions regulate who can access and alter files and directories on a Linux system.

In Linux, who is eligible to gain access to files?

  1. Owner: The user who is the directory's or file's owner.

  2. Group: A collection of users who may require access to the files.

  3. Others: All other individuals not affiliated with the group or the owner.

-rwxrwxrwx 1 vagrant vagrant 3771 Aug 3 21:56 Nigeria

The first group of permission (rwx) is for the owner.

 The second group of permission (rwx) is for the group.

 The third group of permission (rwx) is for other users

Enter fullscreen mode Exit fullscreen mode

They may receive the following permissions:

  • Read (r): This permission command allows you to view or read the file or directory.

  • Write (w): This permission allows you to modify a file or directory.

  • Execute (x): This permission allows you to run the file or directory.

How to tell a file and directory apart?

(d) indicates that the document is a directory while (-) indicates that it is a file.

-rw-r--r-- 1 vagrant vagrant 3771 Aug 3 21:56 .bashrcdrwx------ 2 vagrant vagrant 4096 Aug 14 16:56 .cache-rw-r--r-- 1 vagrant vagrant 807 Aug 3 21:56 .profiledrwx------ 2 vagrant vagrant 4096 Aug 14 16:56 .ssh-rw------- 1 vagrant vagrant 11048 Sep 17 21:03 .viminfo

Enter fullscreen mode Exit fullscreen mode

How to specify permissions?

There are three methods for specifying permissions:

  • The use of octal notation.

  • The symbolic approach.

Octal Notation Method

Linux file and directory permissions can be represented using octal (base-8) numbers using the octal notation approach. It's an efficient approach to communicate authorization settings that use numbers.

Each permission (read, write, execute) is assigned a numeric value and they are:

  1. Read (r) is represented by the value 4.

  2. Write (w) is represented by the value 2.

  3. Execute (x) is represented by the value 1.

You must add these values for each permission type (owner, group, and others) in order to use octal notation. This indicates that the number must be 7 for any of the actors to have full permission.

Example:

A file that has permission 765 implies that:

  • the owner has permission to read(4), write(2) and execute(1) which totals (7).

  • the users in the group has permission to read(4) and write(2) which totals (6).

  • the other users has permission to read(4) and execute (1) which totals (5).

The Symbolic Method

This approach makes use of operators and enables the specification of permission using single-letter abbreviations.

There are three main components to this method's basic structure :

  • Who: The following letters can be used to denote different authorization categories:

  • Operator: The following symbols can be used to denote the operation you wish to carry out:

  • Permissions: The specific permissions you wish to request are represented by letters:

Changing file permissions

You can change file permissions in Linux using the chmod command which means change mode. There are multiple ways to specify the new permissions, including the symbolic method and the absolute (octal) method.

Examples:

Using the symbolic notation to assign permissions to files or directories:

  • chmod u+r file.txt (This command adds read permission to the owner of file.txt).

  • chmod g+rw file.txt (This command adds both read and write permissions to the group of file.txt).

  • chmod g=rw file.txt (This command sets the group permissions of file.txt to read and write only.

  • chmod -R u+rw directory (This command adds read and write permissions to the owner recursively for all files and subdirectories within directory).

Using the Octal method to assign permissions to files and directories:

  • chmod 755 file.txt (This command sets the permissions of file.txt to read, write, and execute for the owner, and only read and execute for the group and others).

  • chmod 640 file.txt (This command sets the permissions of file.txt to read and write for the owner, read-only for the group, and no permissions for others).

  • chmod -R 644 directory (This command sets the permissions of all files and subdirectories within directory to read and write for the owner and read-only for the group and others).

Conclusion

Linux file permissions are essential for regulating access to files and directories on a Linux system, and you can modify the permissions of the files and directories using any of these techniques.

Top comments (0)