DEV Community

K-Sato
K-Sato

Posted on • Edited on

72 18

Understanding Linux Permissions

Table of contents

Introduction

The multi-user capability of Unix-like systems is a feature that is deeply ingrained into the design of the operating system.

File Permissions

On a Linux system, each file and directory is assigned access rights for the owner of the file.

You can check the permission settings with ls -l.

$ ls -l 
drwxr-xr-x. 13 root  root  1027 Jan  3 12:32 bin/cat
Enter fullscreen mode Exit fullscreen mode

Let's explore what drwxr-xr-x. 13 root root 1077 Jan 3 12:32 bin/cat means one by one.

Command Meaning
d File Type
rwxr-xr-x. File Mode
13 Number of links
root The owner of the file
root The group the file belongs to
1027 Size of the file
Jan 3 12:32 Time Stamp
bin/cat The name of the file/directory

File Type

Command File Type
- File
d Directory
l Symbolic Link

File Mode

The r letter means the user has permission to read the file/directory. The w letter means the user has permission to write the file/directory. And the x letter means the user has permission to execute the file/directory.

Command Meaning
r read
w write
x execute
- not allowed

Let's take a look at the 9 letters in the command.
The first 3 letters show the permissions for the file owner, the second 3 letters show the permissions for the group owner and the last 3 letters show the permissions for other users.

rwx/ r-x/ r-x/

Owner: rwx
Group: r-x
Users: r-x
Enter fullscreen mode Exit fullscreen mode

Change File Modes

The chmod command is used to change the permissions of a file or directory.

Octal Mode

Each permission may be specified with an octal number: read = 4; write = 2; execute = 1; no permission = 0.

Meaning  Number
read(r) 4
write(w) 2
execute(x) 1

Example

The command below means giving permissions to read(4), write(2) and execute(1) to the owner and permissions to read(4) and execute(1) to the group user and permissions to read(4) to other users.

chmod 754 myfile
Enter fullscreen mode Exit fullscreen mode

Symbolic Mode

The below is the basic syntax of chmod.

% chmod who operator permission filename
Enter fullscreen mode Exit fullscreen mode

You can use the following commands to change modes.

Command Meaning
u(user) user access
g(group) group access
o(other) other access
a(all) user, group, and other access
Command Meaning
+ add specified permissions
- remove specified permissions
= set the specified permissions

Example

In the following example, read permission are taken away from others.

% chmod o-r filea
Enter fullscreen mode Exit fullscreen mode

In the following example, read and execute permissions are added for user, group, and others.

$ chmod a+rx fileb
Enter fullscreen mode Exit fullscreen mode

In the following example, read, write, and execute permissions are assigned to the group.

$ chmod g=rwx filec
Enter fullscreen mode Exit fullscreen mode

References

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (71)

Collapse
 
david_j_eddy profile image
David J Eddy

When it comes to Linux I make it a point to read even intro level articles like this one. Why? 'cause I am constantly learning new things, like I did here.

Thank you for this. Keep up the good posting!

Collapse
 
k_penguin_sato profile image
K-Sato

Thank you for your kind words!

Collapse
 
ferricoxide profile image
Thomas H Jones II

If you really want to get into powerful permissioning systems, take a look at extended filesystem access control lists (via the setfacl and getfacl utilities), extended attributes (xattrs managed via the chattr and lsattr commands) and, the ultimate cause of headaches, SELinux.

If you're running an Internet-facing system, these are all security-extensions that you want to be reasonably well versed in.

Collapse
 
aghost7 profile image
Jonathan Boudreau

There's also suid/sgid permissions. Normally, when you execute a program, it will run as the user which called it. suid will instead run the program as the owner of the file. For example, if you are logged in as user developer and try to execute a suid program owned by root, it will execute as root instead of developer.

su, sudo, passwd rely on suid to work.

Collapse
 
ferricoxide profile image
Thomas H Jones II

The extension to suid-/sgid-enabled operations being that, when you run auditing services on a system, actions are logged both by actual executing-user and effective executing user.

Collapse
 
daisp profile image
Danny Priymak • Edited

This article did not introduce anything brand new to me, but nonetheless very concise and well written!
Thank you for sharing.

Collapse
 
k_penguin_sato profile image
K-Sato

Thank you for taking the time to read it!!

Collapse
 
arunschirps profile image
Arun

From what I know, I guess you can forgo "a" in the "a+rx".

Collapse
 
k_penguin_sato profile image
K-Sato

Thank you for sharing your knowledge:)!

Collapse
 
djassam profile image
Mike Boro

This concise guide on Linux permissions provides essential insights for users. Demystifying the intricacies, it empowers individuals to navigate and control their system effectively. A valuable resource for anyone seeking clarity on the nuanced world of Linux permissions. TC Lottery MOD APK

Collapse
 
gambinozeyda profile image
GambinoZeyda

Buca escort, bulmak için Buca Eskort adresine gir buca bayan eskort, escort, buca escortlar, buca escort kızlar seninle.
buca escort escort buca

Collapse
 
babak_painex_72157a69bd5b profile image
Babak Painex • Edited

This article is a great resource for anyone considering solar-powered surveillance options. The guide on Solar Mobile Surveillance Trailers in Indio explains the benefits of these mobile units and how they offer flexible, eco-friendly security solutions. If you're looking to enhance your security while keeping things green, this is a must-read!

Collapse
 
hsolvijay009 profile image
vijay

The structured table of contents makes navigation effortless. I am the best dietitian in Vaishali, offering health clinics near Indirapuram. My recent blog post is live, so don’t miss it! When seeking the best dietitian in Vaishali, it's essential to consider professionals who offer personalized and evidence-based nutritional guidance. One such expert is, a certified dietitian with over a decade of experience, specializing in areas ranging from pediatric nutrition to geriatric care. Her holistic approach ensures that dietary plans are tailored to individual needs, promoting sustainable health outcomes.

Dr. Gupta practices at MoTo Nutrition, a renowned health clinic that has earned a reputation as a leading health clinic near Indirapuram. MoTo Nutrition is dedicated to providing convenient, customized, and compassionate care, making it a preferred choice for many seeking nutritional counseling in the region.

Another notable institution is the Max Super Speciality Hospital in Vaishali, which houses a team of expert dietitians proficient in creating customized meal plans for various health conditions. Their comprehensive approach addresses the unique requirements and challenges of each patient, ensuring effective dietary management.

For those closer to Indirapuram, the Shanti Gopal Hospital stands out as a distinguished multi-super specialty hospital. Recognized as one of the top hospitals in Ghaziabad, it offers a range of healthcare services, including expert nutritional counseling. Their team of dedicated specialists provides personalized care, ensuring that patients receive comprehensive dietary guidance tailored to their health needs.

In addition to these, LYF Hospital, located in Indirapuram, is a multi-specialty hospital equipped with advanced healthcare facilities and the latest diagnostic services. Their team of experts includes dietitians who offer personalized nutritional advice, contributing to the hospital's reputation as a trusted healthcare provider in the region.

For those seeking more personalized attention, Dietitian Vaishali Sharma is recognized as a promising nutritionist in the New Delhi and NCR regions. She offers tailored dietary plans and nutritional counseling, focusing on individual health goals and dietary preferences.

When choosing a dietitian or health clinic, it's crucial to consider factors such as the practitioner's experience, areas of specialization, and the comprehensiveness of the services offered. Whether you're aiming to manage a specific health condition, achieve weight loss, or enhance overall well-being, the best dietitian in Vaishali and the leading health clinics near Indirapuram are equipped to guide you on your journey to better health.

Collapse
 
k2t0f12d profile image
Bryan Baldwin

chattr +i filename

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay