Linux File Permission

Linux Permissions: A Beginner's Guide

Linux permissions are a system of rules that control who can access and modify files and directories. Permissions are set for the owner of the file or directory, the group that the file or directory belongs to, and everyone else.

Permission symbols

Linux permissions are represented by three symbols:

  • r: Read permission

  • w: Write permission

  • x: Execute permission

Each symbol can be either present or absent, indicating whether or not the corresponding permission is granted.

Permission values

Each permission symbol has a corresponding numeric value:

  • r: 4

  • w: 2

  • x: 1

The sum of the numeric values for the permissions granted to a particular user or group is called the permission mode.

Example

The following example shows the permissions for a file named myfile.txt:

drwxr-xr-x 1 ubuntu ubuntu 4096 Oct 28 15:52 myfile.txt

The first symbol, d, indicates that myfile.txt is a directory. The next three symbols, rwx, indicate that the owner of the directory has read, write, and execute permission. The next three symbols, r-x, indicate that the group that the directory belongs to has read and execute permission, but not write permission. The last three symbols, r-x, indicate that everyone else has read and execute permission, but not write permission.

Setting permissions

Permissions can be set using the chmod command. The syntax for the chmod command is as follows:

chmod <mode> <file or directory>

The mode can be specified in two ways:

  • Numeric mode: This is a three-digit number that represents the permission mode for the owner, group, and others.

  • Symbolic mode: This is a string of characters that indicates the permissions to be granted or denied.

Example

The following example shows how to change the permissions for the file myfile.txt so that everyone has read and write permission:

chmod a+rw myfile.txt

This will change the permissions for myfile.txt to 777.

Linux permissions are a powerful tool for controlling access to files and directories. By understanding how permissions work, you can ensure that your files and directories are protected from unauthorized access and modification.

0
Subscribe to my newsletter

Read articles from ABHIJEET MAHAJAN directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ABHIJEET MAHAJAN
ABHIJEET MAHAJAN

Tech Entusiast and DevOps Practitioner