Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thedavidyoungblood/030e911dd05da4ecf7bd163ca4609227 to your computer and use it in GitHub Desktop.

Select an option

Save thedavidyoungblood/030e911dd05da4ecf7bd163ca4609227 to your computer and use it in GitHub Desktop.
The Complete Systematic breakdown of - Unix -aka- Linux - PermissionModes.md

The Complete Systematic breakdown of - Unix -aka- Linux - PermissionModes

The complete, systematic breakdown of Unix/Linux permission modes requires enumerating every valid combination, and grouping them into mutually exclusive, collectively exhaustive categories โ€” across all axes:

  • Axis 1: File type (1st char)
  • Axis 2: Owner / Group / Others permission triplets
  • Axis 3: Permission levels (r/w/x combinations)
  • Axis 4: Special bits (setuid, setgid, sticky)
  • Axis 5: Numerical representation (octal)

Below is the full, formal structure. We will proceed layer by layer โ€” from simplest to full combination space.


๐Ÿงญ LEVEL 1 โ€” File Type (Position 1)

Symbol Type Description Typical Example
- Regular file Standard file -rw-r--r--
d Directory Folder drwxr-xr-x
l Symbolic link Pointer to another file lrwxrwxrwx
c Character device Stream I/O device /dev/tty
b Block device Block I/O device /dev/sda
p FIFO / named pipe IPC channel /tmp/fifo_pipe
s Socket IPC socket /var/run/docker.sock

โ†’ 7 exhaustive file-type classes, mutually exclusive.


๐Ÿงฉ LEVEL 2 โ€” Permission Triplets

Each of the next 9 bits (positions 2โ€“10) describe permissions:

  • Owner (u) = bits 2โ€“4
  • Group (g) = bits 5โ€“7
  • Others (o) = bits 8โ€“10

Each triplet can take one of 8 possible values (2ยณ = 8):

Triplet r w x Binary Octal Meaning
--- 0 0 0 000 0 no permissions
--x 0 0 1 001 1 execute only
-w- 0 1 0 010 2 write only
-wx 0 1 1 011 3 write + execute
r-- 1 0 0 100 4 read only
r-x 1 0 1 101 5 read + execute
rw- 1 1 0 110 6 read + write
rwx 1 1 1 111 7 full access

โ†’ Each permission triplet = 8 possibilities.


๐Ÿ”ข LEVEL 3 โ€” Total Basic Permission Space

Since we have 3 triplets (user, group, others):

$$8^3 = 512 \text{ unique permission combinations}$$

Each combination corresponds to an octal triplet (XYZ):

  • X = owner permissions (0โ€“7)
  • Y = group permissions (0โ€“7)
  • Z = others permissions (0โ€“7)

Example mappings:

Symbolic Octal Binary (9 bits) Meaning
rwxr-xr-x 755 111101101 Executable for all, modifiable by owner
rw-r--r-- 644 110100100 Readable by all, writable by owner
rwx------ 700 111000000 Private executable
rw------- 600 110000000 Private file
rwxrwxrwx 777 111111111 Everyone full access (dangerous)
---------- 000 000000000 Completely inaccessible

๐Ÿงฎ LEVEL 4 โ€” Full 4-Digit Octal Representation (Special Bits Included)

We now add the special bits (the first octal digit):

Bit Octal Value Symbolic Indicator Scope Meaning
setuid 4 s in user exec position user run as file owner
setgid 2 s in group exec position group run as fileโ€™s group / inherited group
sticky 1 t in others exec position others only file owner can delete in shared dir

These three bits form the most significant octal digit, ranging from 0โ€“7:

High Digit Meaning
0 No special bits
1 Sticky bit only
2 Setgid only
3 Setgid + sticky
4 Setuid only
5 Setuid + sticky
6 Setuid + setgid
7 All three set

๐Ÿšฉ LEVEL 4 Summary: Full Octal Mode Space

Octal Form Composition Example Symbolic Meaning
0XYZ No special bits -rwxr-xr-x Normal file/dir
1XYZ Sticky bit drwxrwxrwt Shared dir like /tmp
2XYZ Setgid rwxr-sr-x Group inheritance
3XYZ Setgid + Sticky rwxr-sr-t Sticky + group inheritance
4XYZ Setuid rwsr-xr-x Execute as owner
5XYZ Setuid + Sticky rwsr-xr-t Owner exec + sticky
6XYZ Setuid + Setgid rwsr-sr-x Owner + group elevation
7XYZ All special bits rwsr-sr-t Full privilege/sticky

Each XYZ expands to 512 combinations, so full space:

$$8 \times 512 = 4096 \text{ total possible permission combinations}$$


๐Ÿงฑ LEVEL 5 โ€” Semantic Groupings (Logical Classes)

To make 4096 manageable, we can classify symbolically and semantically:

A. Visibility Control

Category Definition Examples (Octal)
Private Only owner can access 700, 600
Shared Group Group can read/write 770, 660
Public Read Anyone can read 755, 644
Public Write Anyone can write 777 (insecure)
No Access No one can read/write 000

B. Execution Control

Category Definition Example
Executable At least one x bit set 755, 775, 711
Non-executable No x bits 644, 600, 664

C. Special Behavior

Category Effect Example
setuid Execute as owner /usr/bin/passwd (4755)
setgid Execute as group / inherited group /usr/bin/mail (2755)
sticky Only owner can delete /tmp (1777)

D. Safety/Exposure

Level Description Example
Secure Restricted to owner 600, 700
Controlled Group-shared 660, 770
Exposed Public readable 644, 755
Dangerous Public writable 666, 777

๐Ÿงฉ LEVEL 6 โ€” Expanded Enumeration by Octal Category

Owner (first triplet / X digit)

X Owner Permissions Symbolic Binary
0 --- none 000
1 --x execute 001
2 -w- write only 010
3 -wx write + exec 011
4 r-- read only 100
5 r-x read + exec 101
6 rw- read + write 110
7 rwx full 111

Same table applies to Group (Y) and Others (Z).

โ†’ Cross product: ( 8 \times 8 \times 8 = 512 ).


๐Ÿงฐ LEVEL 7 โ€” Practical Canonical Sets

Category Octal Symbolic Use Case
Private files 600 rw------- SSH keys, config
Private dirs 700 rwx------ Home directories
Group collaboration 660 rw-rw---- Shared writable files
Shared dir 770 rwxrwx--- Group projects
Public readable 644 rw-r--r-- Web docs
Public executable 755 rwxr-xr-x Scripts, binaries
Sticky shared dir 1777 drwxrwxrwt /tmp
Setuid binary 4755 rwsr-xr-x passwd, sudo
Setgid directory 2755 rwxr-sr-x Shared team folder

๐Ÿงฎ LEVEL 8 โ€” Symbolic Manipulation (chmod algebra)

Symbolic operators in chmod:

Operator Meaning
+ Add permission
- Remove permission
= Set exactly

Example rules:

  • chmod u+x file โ†’ add execute for owner
  • chmod go-w file โ†’ remove write for group/others
  • chmod a=r file โ†’ set everyone to read-only

Shorthand classes:

Class Scope
u user (owner)
g group
o others
a all (u+g+o)

๐Ÿ” LEVEL 9 โ€” Interdependencies (Completeness Map)

Dimension Values Mutually Exclusive? Collectively Exhaustive?
File type 7 โœ… โœ…
Permission triplet 8 โœ… โœ…
Scope (u/g/o) 3 โœ… โœ…
Special bits 8 โœ… โœ…
Octal representation 0000โ€“7777 โœ… โœ…

So the Cartesian product space of possible permission states is:

$$7 \text{(types)} \times 8 \text{(special bits)} \times 512 \text{(permissions)} = 28,672 \text{ possible symbolic states}$$

Thatโ€™s the complete universe of Unix file mode strings.


๐Ÿง  LEVEL 10 โ€” Conceptual Summary Tree (Taxonomy)

Unix Mode (10-char)
โ”œโ”€โ”€ File Type (7)
โ”‚   โ”œโ”€โ”€ Regular (-)
โ”‚   โ”œโ”€โ”€ Directory (d)
โ”‚   โ”œโ”€โ”€ Symlink (l)
โ”‚   โ”œโ”€โ”€ Char Dev (c)
โ”‚   โ”œโ”€โ”€ Block Dev (b)
โ”‚   โ”œโ”€โ”€ FIFO (p)
โ”‚   โ””โ”€โ”€ Socket (s)
โ”œโ”€โ”€ Permissions (512 = 8ยณ)
โ”‚   โ”œโ”€โ”€ User (8)
โ”‚   โ”œโ”€โ”€ Group (8)
โ”‚   โ””โ”€โ”€ Others (8)
โ””โ”€โ”€ Special Bits (8)
    โ”œโ”€โ”€ None (0)
    โ”œโ”€โ”€ Sticky (1)
    โ”œโ”€โ”€ Setgid (2)
    โ”œโ”€โ”€ Setgid+Sticky (3)
    โ”œโ”€โ”€ Setuid (4)
    โ”œโ”€โ”€ Setuid+Sticky (5)
    โ”œโ”€โ”€ Setuid+Setgid (6)
    โ””โ”€โ”€ All (7)

โœ… TL;DR โ€” The Exhaustive Map

Dimension Possibilities Description
File Types 7 - d l c b p s
Permission Triplets per Entity 8 each --- --x -w- -wx r-- r-x rw- rwx
Entities 3 user, group, others
Special Bits 8 0โ€“7 combinations of sticky/setuid/setgid
Full Permission Octals 0000โ€“7777 4096 unique permission sets
Total Symbolic Mode Strings (with file types) 28,672 the complete universe

S๐Ÿ‘€ ALSO: "FULL TABLE"

SPREADSHEET-LINK: Unix_Permission_Combinations_as-a-Combinatory-Table


What youโ€™re seeing in the spreadsheet for 4-digit octal's, (like 6667 in the sheet) is completely valid but not whatโ€™s usually shown by ls -l. Hereโ€™s why that happens, and how to interpret it correctly.


๐Ÿงฎ 1. Octal Permissions Have Two Layers

Form Digits Meaning Example Typical Use
3-digit XYZ Base permissions only (owner, group, others) 755 โ†’ rwxr-xr-x Normal chmod/ls
4-digit SXYZ Adds the special bits (setuid, setgid, sticky) in the leading digit 4755 โ†’ rwsr-xr-x Complete representation

So the tableโ€™s 4-digit octals (e.g., 6667) are full 12-bit modes, not just the 9-bit permission triplets.


๐Ÿงฉ 2. The Composition Explained

The 12-bit mode looks like this internally:

Bit Range Octal Digit Role
12โ€“10 S special bits (setuid/setgid/sticky)
9โ€“7 X owner permissions
6โ€“4 Y group permissions
3โ€“1 Z others permissions

So:

Mode = (SpecialBits ร— 512) + (Owner ร— 64) + (Group ร— 8) + (Others)

In octal shorthand:

SXYZ

โš™๏ธ 3. Example Breakdown: 6667

Component Octal Binary Meaning
Special bits 6 110 setuid + setgid
Owner 6 110 read + write
Group 6 110 read + write
Others 7 111 read + write + execute
โ†’ Symbolic: rwSrwSrwx execute under user/group privileges

Interpretation:

  • setuid + setgid are active (from the leading 6).
  • Owner and group have rw-.
  • Others have rwx.

So this is not a mistake โ€” itโ€™s simply the complete encoding, where the leading octal digit represents privilege bits.


๐Ÿงฑ 4. When to See 3 vs 4 Digits

Context Digits Used Why
Normal file (chmod 755, ls -l) 3 No special bits โ†’ leading 0 omitted
Special binary (e.g., passwd, sudo) 4 setuid or setgid active
Secure directories like /tmp 4 Sticky bit active (e.g. 1777)

So in the sheet:

  • Rows with 000X โ†’ ordinary permissions (same as 3-digit form).
  • Rows with 1XXX, 2XXX, 4XXX, etc. โ†’ special bits applied.

โœ… 5. TL;DR Summary

Octal Digit Position Meaning Bit Flags
1st (thousands place) Special bits 4 = setuid, 2 = setgid, 1 = sticky
2nd Owner perms 4 = read, 2 = write, 1 = exec
3rd Group perms same
4th Others perms same

Examples:

Octal Symbolic Meaning
0644 rw-r--r-- Normal text file
0755 rwxr-xr-x Executable file
1777 rwxrwxrwt Sticky shared directory (/tmp)
4755 rwsr-xr-x setuid program (runs as owner)
2755 rwxr-sr-x setgid program (runs as group)
6667 rwSrwSrwx both setuid/setgid + full others access

In short: ๐Ÿ‘‰ 3-digit = regular permissions ๐Ÿ‘‰ 4-digit = full mode (including privilege bits) ๐Ÿ‘‰ The sheet correctly uses 4-digit form (SXYZ) so you can represent all 4096 possible combinations โ€” not just the 512 basic ones.




[!NOTE] ### NOTE:

This is just provided as conceptual research, documentation, for informational-purposes only, etc., and has not been fully battle tested or vetted, however would appreciate hearing and learning about any implementations, and shared learnings. (Unless otherwise explicitly stated by the author.)


@TheDavidYoungblood

๐Ÿค Let's Connect!

LinkedIn // GitHub // Medium // Twitter/X



A bit about David Youngblood...


David is a Partner, Father, Student, and Teacher, embodying the essence of a true polyoptic polymath and problem solver. As a Generative AI Prompt Engineer, Language Programmer, Context-Architect, and Artist, David seamlessly integrates technology, creativity, and strategic thinking to co-create systems of enablement and allowance that enhance experiences for everyone.

As a serial autodidact, David thrives on continuous learning and intellectual growth, constantly expanding his knowledge across diverse fields. His multifaceted career spans technology, sales, and the creative arts, showcasing his adaptability and relentless pursuit of excellence. At LouminAI Labs, David leads research initiatives that bridge the gap between advanced AI technologies and practical, impactful applications.

David's philosophy is rooted in thoughtful introspection and practical advice, guiding individuals to navigate the complexities of the digital age with self-awareness and intentionality. He passionately advocates for filtering out digital noise to focus on meaningful relationships, personal growth, and principled living. His work reflects a deep commitment to balance, resilience, and continuous improvement, inspiring others to live purposefully and authentically.


Personal Insights

David believes in the power of collaboration and principled responsibility in leveraging AI for the greater good. He challenges the status quo, inspired by the spirit of the "crazy ones" who push humanity forward. His commitment to meritocracy, excellence, and intelligence drives his approach to both personal and professional endeavors.

"Hereโ€™s to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holesโ€ฆ the ones who see things differently; theyโ€™re not fond of rules, and they have no respect for the status quoโ€ฆ They push the human race forward, and while some may see them as the crazy ones, we see genius, because the people who are crazy enough to think that they can change the world, are the ones who do." โ€” Apple, 1997


My Self-Q&A: A Work in Progress

Why I Exist? To experience life in every way, at every moment. To "BE".

What I Love to Do While Existing? Co-creating here, in our collective, combined, and interoperably shared experience.

How Do I Choose to Experience My Existence? I choose to do what I love. I love to co-create systems of enablement and allowance that help enhance anyone's experience.

Who Do I Love Creating for and With? Everyone of YOU! I seek to observe and appreciate the creativity and experiences made by, for, and from each of us.

When & Where Does All of This Take Place? Everywhere, in every moment, of every day. It's a very fulfilling place to be... I'm learning to be better about observing it as it occurs.

A Bit More...

I've learned a few overarching principles that now govern most of my day-to-day decision-making when it comes to how I choose to invest my time and who I choose to share it with:

  • Work/Life/Sleep (Health) Balance: Family first; does the schedule agree?
  • Love What You Do, and Do What You Love: If you have what you hold, what are YOU holding on to?
  • Response Over Reaction: Take pause and choose how to respond from the center, rather than simply react from habit, instinct, or emotion.
  • Progress Over Perfection: One of the greatest inhibitors of growth.
  • Inspired by "7 Habits of Highly Effective People": Integrating Coveyโ€™s principles into daily life.

Final Thoughts

David is dedicated to fostering meaningful connections and intentional living, leveraging his diverse skill set to make a positive impact in the world. Whether through his technical expertise, creative artistry, or philosophical insights, he strives to empower others to live their best lives by focusing on what truly matters.

โ€” David Youngblood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment