CIS120 Linux Fundamentals by Scott Shaper

Linux Permissions

Think of Linux permissions like a security system for your files and folders. Just like how you might have different keys for different rooms in your house, Linux uses permissions to control who can access and modify your files. Understanding permissions helps you keep your work safe and share it with others when needed.

Quick Reference

Permission Type What It Does Common Use
Read (r) View file contents Opening files, listing directories
Write (w) Modify contents Editing files, creating/deleting files
Execute (x) Run programs/scripts Running commands, accessing directories

When to Use Permissions

User Categories

Think of user categories like different groups of people who might need access to your files:

Category Who It Includes Example
Owner (u) You, the file creator Like being the owner of a house
Group (g) Users in the same group Like family members sharing a house
Others (o) Everyone else Like visitors or guests

Viewing Permissions

linux permissions

The above image break down the permissions of a file. Lets start with the code that would match those permissions.

-rwxrw-r-- 1 user group  4096 Jul 10 14:55 file.txt

Now lets break this down:

Every file and directory will have an owner, a group and an other. Each one of this will have a set of permissions assigned to them. In our example the owner is the user and the group is the group name. The other is everyone else.

The permissions are represented by the letters r, w, and x. r stands for read, w stands for write, and x stands for execute. The permissions are assigned to the owner, the group, and the other in the order of rwx.

In our example the owner has read, write, and execute permissions. The group has read and execute permissions. The other has read permissions.

Numeric Permissions

Numeric permissions in Linux use a three-digit number system (like 755 or 644) to represent file permissions. Each digit represents a different user category (owner, group, others) and is calculated by adding up the values of individual permissions:

To understand how this works, let's break it down:

  1. First Digit (Owner): Controls what the file owner can do
  2. Second Digit (Group): Controls what group members can do
  3. Third Digit (Others): Controls what everyone else can do

For example, the number 7 (4+2+1) means full permissions (read, write, execute). Here's how to calculate common permission numbers:

Number Calculation Permissions What It Means
7 4+2+1 rwx Full access (read, write, execute)
6 4+2 rw- Can read and modify, but not execute
5 4+1 r-x Can read and execute, but not modify
4 4 r-- Read only access
3 2+1 -wx Can write and execute, but not read
2 2 -w- Write only access
1 1 --x Execute only access
0 0 --- No access at all

When you see a three-digit number like 755, it means:

This system makes it easy to set permissions with a single command. For example, chmod 755 file.txt sets the permissions to rwxr-xr-x in one step.

Common Numeric Permission Examples

# 755: Owner has full access, others can read and execute
# rwxr-xr-x
chmod 755 script.sh

# 644: Owner can read and write, others can only read
# rw-r--r--
chmod 644 document.txt

# 750: Owner has full access, group can read and execute, others have no access
# rwxr-x---
chmod 750 private/

# 600: Only owner can read and write
# rw-------
chmod 600 secret.txt

Symbolic Mode

Think of symbolic mode like using simple words to set permissions. You can use letters to specify who gets what permissions:

Part What It Means Example
u (user) File owner You
g (group) Group members Your project team
o (others) Everyone else Other students
a (all) All users Everyone

You can use these operators to change permissions:

Operator What It Does Example
+ Add permission Add execute permission
- Remove permission Remove write permission
= Set exact permissions Set read and write only

Symbolic Mode Examples

# Add execute permission for owner
chmod u+x script.sh

# Remove write permission from group
chmod g-w document.txt

# Set read and write for others
chmod o=rw shared.txt

# Add execute for all users
chmod a+x program

# Set read and execute for group and others
chmod go=rx file.txt

What do the other parts mean?

-rwxrw-r-- 1 user group  4096 Jul 10 14:55 file.txt

To the other parts of the code example are broken down below:

Tips for Success

Common Mistakes to Avoid

Best Practices