|

Linux CLI 17 ๐Ÿง Owner, group member and the rest

Every file and directory in Linux has permissions that control who can do what. Understanding permissions is essential for security and collaboration.


Reading ls -l Output

$ ls -l
-rw-r--r--  1 kronos users  1024 Jan 15 10:30 1.txt
drwxr-xr-x  2 kronos users  4096 Jan 15 10:30 d2

Let’s break down each column:

-rw-r--r--  1 kronos users  1024 Jan 15 10:30 1.txt
โ”‚           โ”‚ โ”‚      โ”‚      โ”‚    โ”‚           โ”‚
โ”‚           โ”‚ โ”‚      โ”‚      โ”‚    โ”‚           โ””โ”€โ”€ Filename
โ”‚           โ”‚ โ”‚      โ”‚      โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Last modification date
โ”‚           โ”‚ โ”‚      โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ File size (bytes)
โ”‚           โ”‚ โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Group
โ”‚           โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Owner
โ”‚           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Hard links count
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ File type + permissions

File Type โ€” The First Character

CharacterTypeExample
-Regular file-rw-r--r--
dDirectorydrwxr-xr-x
lSymbolic linklrwxrwxrwx
cCharacter devicecrw-rw-rw-
bBlock devicebrw-rw----
pPipe (FIFO)prw-r--r--
sSocketsrwxrwxrwx

Examples:

-rw-r--r--   regular file
drwxr-xr-x   directory
lrwxrwxrwx   symbolic link
crw-rw-rw-   character device (e.g., /dev/tty)
brw-rw----   block device (e.g., /dev/sda)
prw-r--r--   named pipe
srwxrwxrwx   socket

The Three Permission Groups

The next 9 characters (positions 2โ€“10) are divided into three groups of three:

-  rw-  r--  r--
โ”‚  โ”‚    โ”‚    โ”‚
โ”‚  โ”‚    โ”‚    โ””โ”€โ”€ Permissions for the "rest" (others)
โ”‚  โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Permissions for group members
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Permissions for the owner
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ File type
GroupCharactersApplies To
1st group2, 3, 4Owner’s permissions
2nd group5, 6, 7Group members’ permissions
3rd group8, 9, 10Everyone else (the rest)

The Three Permission Types

Within each group of three:

r w x
โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ””โ”€โ”€ x = execute permission
โ”‚ โ””โ”€โ”€โ”€โ”€ w = write permission
โ””โ”€โ”€โ”€โ”€โ”€โ”€ r = read permission
PositionSymbolMeaning
1strRead permission
2ndwWrite permission
3rdxExecute permission
Missing-No permission

What Each Permission Means

PermissionOn a FileOn a Directory
r (read)View file contentsList directory contents (ls)
w (write)Modify file contentsCreate/delete files in directory
x (execute)Run file as programEnter the directory (cd)

Important: x on a directory means you can enter it with cd. Without x, you can’t cd into it โ€” even if you have r.


Example Analysis

Example 1: 1.txt โ€” A Regular File

-rw-r--r--  1 kronos users  1024 Jan 15 10:30 1.txt

Breaking it down:

-  rw-  r--  r--
โ”‚  โ”‚    โ”‚    โ”‚
โ”‚  โ”‚    โ”‚    โ””โ”€โ”€ Rest: read only
โ”‚  โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Group: read only
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Owner: read and write
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Regular file
WhoPermissionsMeaning
Ownerrw-Can read and write (modify)
Groupr--Can only read
Restr--Can only read

Owner: kronos โ€” the user who owns the file
Group: users โ€” the group the file belongs to

What each can do:

  • kronos (owner): Read the file, edit it, but cannot execute it
  • Group members: Only read the file
  • Others: Only read the file

Example 2: d2 โ€” A Directory

drwxr-xr-x  2 kronos users  4096 Jan 15 10:30 d2

Breaking it down:

d  rwx  r-x  r-x
โ”‚  โ”‚    โ”‚    โ”‚
โ”‚  โ”‚    โ”‚    โ””โ”€โ”€ Rest: read and enter
โ”‚  โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Group: read and enter
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Owner: read, write, and enter
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Directory
WhoPermissionsMeaning
OwnerrwxCan list, modify (create/delete), and enter
Groupr-xCan list and enter, but not modify
Restr-xCan list and enter, but not modify

What each can do:

  • kronos (owner): Full control โ€” cd in, ls, create/delete files
  • Group members: Enter the directory, see contents, but can’t add/remove files
  • Others: Same as group โ€” can look but not touch

Who Owns What?

TermMeaningExample
OwnerThe user who owns the filekronos
GroupThe group that owns the fileusers
RestEveryone else on the systemโ€”

Visual:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    System                      โ”‚
โ”‚                                                โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ”‚  โ”‚    Owner     โ”‚  โ”‚    Group     โ”‚  โ”‚  Rest  โ”‚โ”‚
โ”‚  โ”‚   kronos     โ”‚  โ”‚    users     โ”‚  โ”‚ Others โ”‚โ”‚
โ”‚  โ”‚              โ”‚  โ”‚              โ”‚  โ”‚        โ”‚โ”‚
โ”‚  โ”‚  rw- (rwx)   โ”‚  โ”‚  r-- (r-x)   โ”‚  โ”‚ r--    โ”‚โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Common Permission Combinations

PermissionsSymbolicOctalMeaning
rwxrwxrwx777Everyone: full access
rwxr-xr-x755Owner: full; others: read+execute
rw-r--r--644Owner: read+write; others: read
rwx------700Owner only: full access
rw-------600Owner only: read+write
rwxr-x---750Owner: full; group: read+execute
rw-rw-r--664Owner+group: read+write; others: read
rwxrwx---770Owner+group: full; others: none

Octal (Numeric) Permissions

Each permission type has a numeric value:

PermissionValue
r (read)4
w (write)2
x (execute)1
- (none)0

Add them up per group:

PermissionCalculationOctal
rwx4 + 2 + 17
rw-4 + 2 + 06
r-x4 + 0 + 15
r--4 + 0 + 04
-wx0 + 2 + 13
-w-0 + 2 + 02
--x0 + 0 + 11
---0 + 0 + 00

Example:

-rw-r--r--   โ†’   6 4 4   โ†’   644
drwxr-xr-x   โ†’   7 5 5   โ†’   755
-rwxr-x---   โ†’   7 5 0   โ†’   750

Complete Example Session

# ============================================
# PART 1: READING LS -L OUTPUT
# ============================================

$ ls -l
-rw-r--r--  1 kronos users  1024 Jan 15 10:30 1.txt
drwxr-xr-x  2 kronos users  4096 Jan 15 10:30 d2
lrwxrwxrwx  1 kronos users    10 Jan 15 10:30 link -> /etc
crw-rw-rw-  1 root   root   1, 3 Jan 15 10:30 /dev/null
brw-rw----  1 root   disk   8, 0 Jan 15 10:30 /dev/sda

# ============================================
# PART 2: ANALYZING PERMISSIONS
# ============================================

# File: 1.txt โ€” regular file
# Owner: kronos โ€” read, write
# Group: users โ€” read
# Rest: read
-rw-r--r--  1 kronos users  1024 Jan 15 10:30 1.txt

# Directory: d2
# Owner: kronos โ€” read, write, enter
# Group: users โ€” read, enter
# Rest: read, enter
drwxr-xr-x  2 kronos users  4096 Jan 15 10:30 d2

# ============================================
# PART 3: PERMISSION MEANING
# ============================================

# For 1.txt:
# Owner kronos: can read and write
# Group users: can read only
# Others: can read only
# Nobody can execute

# For d2 (directory):
# Owner kronos: can cd in, ls, create/delete files
# Group users: can cd in, ls, but not create/delete
# Others: same as group

# ============================================
# PART 4: PRACTICAL EXAMPLES
# ============================================

# A private file โ€” only owner can read/write
-rw-------  1 kronos users  1024 Jan 15 10:30 private.txt

# A shared file โ€” owner and group can read/write
-rw-rw-r--  1 kronos developers  1024 Jan 15 10:30 shared.txt

# An executable script
-rwxr-xr-x  1 kronos users  2048 Jan 15 10:30 script.sh

# A web file โ€” readable by everyone
-rw-r--r--  1 root   root   4096 Jan 15 10:30 /var/www/index.html

# A secret directory โ€” only owner
drwx------  2 kronos users  4096 Jan 15 10:30 .ssh

Quick Reference

File Types (First Character)

SymbolType
-Regular file
dDirectory
lSymbolic link
cCharacter device
bBlock device
pPipe
sSocket

Permission Groups

GroupPositionsApplies To
1st2, 3, 4Owner
2nd5, 6, 7Group members
3rd8, 9, 10The rest (others)

Permission Types

SymbolNameValueOn FileOn Directory
rRead4View contentsList contents
wWrite2Modify contentsCreate/delete files
xExecute1Run programEnter with cd
-None0No accessNo access

Common Octal Values

OctalSymbolicMeaning
644rw-r--r--Owner: rw; others: r
755rwxr-xr-xOwner: rwx; others: rx
700rwx------Owner only
600rw-------Owner only (files)
664rw-rw-r--Owner+group: rw
777rwxrwxrwxEveryone: rwx (rarely needed)

Best Practices

โœ… Do This:

# Files โ€” 644 (rw-r--r--) is the safe default
chmod 644 file.txt

# Directories โ€” 755 (rwxr-xr-x) is the safe default
chmod 755 mydir

# Private files โ€” 600 (rw-------) for sensitive data
chmod 600 ~/.ssh/id_rsa
chmod 600 .env

# Private directories โ€” 700 (rwx------)
chmod 700 ~/.ssh

# Executables โ€” 755 (rwxr-xr-x)
chmod 755 script.sh

โŒ Don’t Do This:

# Don't give everyone everything
chmod 777 file.txt       # โŒ Security risk!
chmod -R 777 /var/www    # โŒ Very dangerous!

# Don't remove execute from directories
chmod -x mydir           # โŒ Can't cd into it

# Don't make scripts non-executable and expect them to run
chmod 644 script.sh
./script.sh              # โŒ Permission denied
chmod +x script.sh       # โœ… Fix

# Don't share sensitive files with group/others
chmod 644 ~/.ssh/id_rsa  # โŒ Private key should be 600!

Common Pitfalls

PitfallProblemSolution
x on directoryNeeded to cd inKeep x on directories
Files without rCan’t readAdd r
Scripts without xCan’t executechmod +x script.sh
Everyone can readSecurity riskUse 600 for private
Confusing owner/groupWrong accessCheck with ls -l
777 on web filesWide open to attacksUse 644 for files, 755 for dirs

Real-World Examples

1. Web Server Files

# HTML files โ€” owner write, all read
-rw-r--r--  1 www-data www-data  index.html

# Directories โ€” owner full, all enter+list
drwxr-xr-x  2 www-data www-data  uploads/

# Never use 777!

2. SSH Keys

# Private key โ€” owner only
-rw-------  1 kronos users  id_rsa

# Public key โ€” readable by all
-rw-r--r--  1 kronos users  id_rsa.pub

# SSH directory โ€” owner only
drwx------  2 kronos users  .ssh/

3. Shared Development

# Team-shared project โ€” group can write
drwxrwxr-x  5 alice developers  project/
-rw-rw-r--  1 alice developers  README.md

4. System Binaries

# Executables โ€” everyone can run
-rwxr-xr-x  1 root root  /usr/bin/ls
-rwxr-xr-x  1 root root  /bin/bash

Visual: Permission Structure

-rw-r--r--  1 kronos users  1024 Jan 15 10:30 1.txt
โ”‚โ””โ”ฌโ”˜โ””โ”ฌโ”˜โ””โ”ฌโ”˜
โ”‚ โ”‚  โ”‚  โ””โ”€โ”€ Rest: read only
โ”‚ โ”‚  โ””โ”€โ”€โ”€โ”€โ”€ Group: read only
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Owner: read + write
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Regular file

POSITIONS:
  1    2 3 4    5 6 7    8 9 10
  โ”‚    โ”‚  โ”‚  โ”‚    โ”‚  โ”‚  โ”‚    โ”‚  โ”‚  โ”‚
  โ”‚    r  w  -    r  -  -    r  -  -
  โ”‚    โ””โ”€โ”€โ”ฌโ”€โ”€โ”˜    โ””โ”€โ”€โ”ฌโ”€โ”€โ”˜    โ””โ”€โ”€โ”ฌโ”€โ”€โ”˜
  โ”‚       โ”‚          โ”‚          โ”‚
  โ”‚    Owner       Group      Rest
  โ”‚
  File type (- = file, d = directory)

Summary

ConceptDescription
First characterFile type (-, d, l, etc.)
Positions 2โ€“4Owner permissions
Positions 5โ€“7Group permissions
Positions 8โ€“10Others permissions
rRead (4)
wWrite (2)
xExecute/Enter (1)
No permission (0)

Key takeaways:

  • ls -l shows permissions in a 10-character string
  • First character = file type
  • Next 9 characters = permissions in three groups (owner, group, rest)
  • Each group has three permissions: read (r), write (w), execute (x)
  • x on a directory means you can cd into it
  • x on a file means you can run it as a program
  • Permission values are summed: r=4, w=2, x=1
  • 644 = files (owner rw, others r)
  • 755 = directories/executables (owner rwx, others rx)
  • 600 = private files (owner only)
  • 777 = dangerous โ€” avoid at all costs

Remember: Permissions control who can do what. The three groups โ€” owner, group, rest โ€” let you set fine-grained access. Use 644 for regular files, 755 for directories and executables, and 600 for sensitive data. Never use 777 โ€” it’s a security hole. And always think: who needs to read this? Who needs to write this? Who needs to execute this?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!