Linux File Permission Decoding

Linux File and Directory Permissions

Introduction To Linux File And Directory Permissions

The Basic Linux Operating System is a clone of the Unix Operating System. Later it has been improved a lot due to its open source license. It is a multi-user Operating System that can be accessed by multiple users simultaneously. But it can be a possibility of security concerns in the system for file or directory access. That means any kind of unsolicited or malign user can change, delete, or corrupt the important data or file system. The Linux File and Directory Permissions are very important to use for the prevention of unsolicited or malign user access.

In Linux, file and directory permissions are used to control access to files and directories. Each file and directory has three types of permissions: read, write, and execute. These permissions can be assigned to the owner of the file, the group associated with the file, and all other users (referred to as “others”).

To make secure data or any files inside your system, the Linux System provides a method called Authorization. This file authorization divided into two levels. Such as:

  • Ownership.
  • Permissions.

So each user for a particular system will be having two authorization methods to assign permissions or access rights to specific users and groups of users. These types of permissions can control the ability of a user to view, change, navigate, or execute the contents of the file system. The below image shows the file permissions in Linux with examples of how the Linux File and Directory Permissions are assigned.

Ownership Of Linux File System or Directories

Every directory or file in the Linux/Unix file system is having 3 types of ownership, as given below;

  1. User: A user is the owner of any file that is created by him. So by default, a file will be the owner of this user who creates it.
  2. Group: A Group means more than one user. That means when multiple users are having access permissions to a particular file is called Group ownership of a file. Suppose you have a project where multiple users are required to access it, then you can use Group ownership. So here instead of assigning the permissions to each user manually, you can create a Group by adding all users to it and then assign permissions to that group so that nobody else should not able to access it.
  3. Other: An user who neither created a file nor belongs to a user Group could able to access a file is called Other.

Linux system is having multiple commands to know the file-related information. But a very common command is ‘ls’ that we are gonna use in our example. I have used this “ls -l” command and got the response with the below data as per my system.

root@DESKTOP-O6Q5JJ7:/home/prakashs# ls -l
total 32
-rwxr-xr-x 1 root root 16688 Nov 28 19:13 code
-rw-r--r-- 1 root root   108 Nov 28 19:13 code.c

Linux File Type Explanation

If you look at the above command, it gives the details of a file having a file permission string. The first character indicates whether it is a regular file, directory, or a symbolic link.

SymbolType
Regular File
dDirectory
lSymbolyc Link
File Type from Symbol

Linux File Permissions

In the Linux file system, there are 3 types of file permissions. basically, it is Read type (r), Write type (w), and Execute Type (x). Symbolically, it is represented as r,w, & x. If you want to see the contents of a file only, then you can give that file with reading (r) permissions. If you want to see the contents of a file only, then you can give that file with writing (w) permissions. If you want to see the contents of a file only, then you can give that file with execute (x) permissions. Even if you want to have multiple permissions for a file then also you can use the combinations.

SymbolPermission
rRead
wWrite
xExecute
Linux File Permission Symbols used in Command line

The next string defines the

Linux File Verses Directory Permissions

The permission is a way of a file or a directory access. You can look at below table how it is different.

PermissionFileDirectory
Read (r)It allows a file to be readIt allows file names in the directory to be read
Write (w)It allows a file to be modifiedIt allows file entries or data in the directory that can be modified
Execute (x)It allows a file that can be executedIt allows access to contents and metadata for entries
Linux File Verses Directory Permissions

Linux File Permission Categories

SymbolCategory
uUser
gGroup
oOther
aAll
Linux File Permission Categories

Groups in Linux System

  • Every user in Linux will have at least one group.
  • A single user also can belong to many groups.
  • Basically, the groups are supposed used to organize the groups.
  • The “groups” command displays a user group.
  • You also can use the command “id -Gn“.

Linux File Permission Change

There are two types of file notation. One is symbolic notation and the other one is numeric notation. To specify the modes and information’s, you can use the Linux command “chmod”

File Item Description
chmodFile mode change command
ugoaUser, Group, Other, All
+-=Add, Subtract, Ser permissions
rwxRead, Write, Execute
Linux File Notation System table

To specify the modes and permissions

Numeric Based File Or Directory Permissions

rwxDescription
000Value for OFF
111Binary value for ON
421Base 10 Value for ON
Linux File Permission based on Numeric Notation

Linux File Octal Permissions

OctalBinaryStringDescriptions
00No permissions
11–xExecute Only permissions
210-x-Write Only permissions
311-wxWrite and Execute permissions (2+1)
4100r–Read Only permissions
5101r-xRead and Execute permissions (4+1)
6110rw-Read and Write permissions (4+2)
7111rwxRead, Write and Execute (4+2+1)
Linux File Octal Permissions

Linux Permission Type Based On Number System

Number permissionsUGO
Symbolicrwxr-xr–
Binary111101100
Decimal754
Linux File Number Permissions

Commonly Used Permissions in Linux

SymbolicOctal
-rwx——700
-rwxr-xr-x555
-rw-rw-r–664
-rw-rw—-660
-rw-r—–644
Commonly Used File Permissions in Linux/Unix

Working With Groups

New files are belongs to your primary Group. The chgrp command used to change the group.

Directory Permissions

The permissions on a directory can affect the files in the directory. If the file permissions look correct, start checking directory permissions. You need to work in your way up to the root.

File Creation Mask

File creation mask determines the default permissions. If no mask were used, the permissions would be:

  • 777 for directories
  • 666 for files.

umask Command

umask [-S] [mode]

It sets the file creation mask to mode, if given. Use -S to for symbolic notation.

umask typeDirectoryFile
Base Permission777666
substract Umask-022-022
Creations Permissions755644
umask type file permissions in Linux

Octal Subtraction is an Estimation

DirectoryFile
Base Permissions777666
Subtract Umask-007-007
Creations Permissions770660*
Octal Subtraction is an Estimation

Common umask modes used in Linux System

  • 022
  • 002
  • 077
  • 007
OctalBinaryDirectory
Permissions
File Permissions
00rwxrw-
11rw-rw-
210r-xr–
311r–r–
4100-wx-w-
5101-w--w-
6110–x
7111
Common umask modes table used in Linux System

Special Modes

  • The umask 0022 is same as the umask 022.
  • chmod 0644 is same as 644
  • The special modes are.
    • setuid
    • setgid
    • sticky
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
Scroll to Top