Linux Permission Management Basics

Permission Management Basics - File Permissions and Security

Linux permission management is the foundation of system security. In this basics guide, you'll safely learn permission mechanisms, risk avoidance techniques, and chmod basics. We focus on common beginner traps and correct solutions.

Table of Contents

  1. Basic Permission Concepts
  2. ⚠️ Common Beginner Traps and Dangerous Patterns
  3. Reading Permissions
  4. chmod - Changing Permissions

1. Basic Permission Concepts

In Linux, all files and directories have 3 types of users and 3 types of permissions.

User Types

  • Owner (u) - File owner
  • Group (g) - Group members
  • Others (o) - Other users

Permission Types

  • Read (r) - Read permission (4)
  • Write (w) - Write permission (2)
  • Execute (x) - Execute permission (1)

Permission Meanings for Files and Directories

Permission File Directory
Read (r) Can read file contents Can list directory contents
Write (w) Can modify file contents Can create/delete files in directory
Execute (x) Can execute as program Can navigate into directory (cd)

2. ⚠️ Common Beginner Traps and Dangerous Patterns

Learn about dangerous operations beginners often make and common misconceptions in Linux permission management to avoid security risks.

🚨 Most Dangerous: chmod 777 Abuse

NEVER do this operation

❌ Dangerous Examples

$ chmod 777 /var/www/html/
$ chmod -R 777 /home/user/
$ chmod 777 /etc/config.php

This is extremely dangerous! Anyone can read, write, and execute the files.

🔥 Dangers of 777

  • Security Breach - Other users can access confidential information
  • System Destruction - Unintended modification/deletion of critical files
  • Malware Infection - Risk of executing malicious code
  • Data Leakage - Unauthorized access to sensitive data

✅ Correct Alternatives

  • Web files: chmod 644 (files) / chmod 755 (directories)
  • Config files: chmod 600 (owner-only access)
  • Executables: chmod 755 or chmod 700
  • Log directories: chmod 750 (group read allowed)

🔍 Common Permission Misconceptions

❌ Mistake: "Can't access = chmod 777 fix"

Symptom: Can't open file, getting errors

Wrong Solution: chmod 777 filename

✅ Correct Approach
  1. Check current permissions: ls -l filename
  2. Grant minimum necessary permissions: chmod 644 filename
  3. Verify ownership: ls -l filename | awk '{print $3 $4}'
  4. Change ownership if needed: sudo chown user:group filename

❌ Mistake: Misusing Recursive Permission Changes

Dangerous command: chmod -R 777 /

Result: Complete system security breakdown

✅ Correct Method
$ find /var/www/html -type f -exec chmod 644 {} \;
$ find /var/www/html -type d -exec chmod 755 {} \;

Set appropriate permissions separately for files and directories

❌ Mistake: Confusing Execute Permission

Common misconception: "Need execute permission to open files"

✅ Correct Understanding
  • Text files: Only read permission (r) needed
  • Script execution: Execute permission (x) required
  • Directory access: Execute permission (x) required
$ chmod 644 document.txt    # Text file
$ chmod 755 script.sh       # Executable script
$ chmod 755 directory/      # Directory

🪤 Specific Traps Beginners Fall Into

Trap 1: Website Won't Display

1

Problem: "403 Forbidden" error appears

2

Wrong Solution: chmod -R 777 /var/www/html/

⚠️

Result: Security vulnerability created!

Correct Solution:

$ sudo find /var/www/html -type d -exec chmod 755 {} \;
$ sudo find /var/www/html -type f -exec chmod 644 {} \;
$ sudo chown -R www-data:www-data /var/www/html/

Trap 2: SSH Private Key Access Denied

1

Problem: "Permission denied (publickey)" error

2

Wrong Solution: chmod 777 ~/.ssh/id_rsa

⚠️

Result: SSH rejects the private key (security feature)

Correct Solution:

$ chmod 700 ~/.ssh/           # Directory
$ chmod 600 ~/.ssh/id_rsa     # Private key
$ chmod 644 ~/.ssh/id_rsa.pub # Public key
$ chmod 600 ~/.ssh/config     # Config file

Trap 3: Script Won't Execute

1

Problem: "Permission denied" when running script

2

Check symptoms: ls -l script.sh-rw-r--r--

Correct Solution:

$ chmod u+x script.sh        # Add execute permission for owner
$ chmod 755 script.sh         # Or set numerically

3. Reading Permissions

Learn to correctly interpret permission information displayed by ls -l command.

Displaying Permission Information

$ ls -l example.txt
-rw-r--r-- 1 user group 1024 Jan 11 10:00 example.txt

Components of Permission Information

1st Character: File Type

  • - Regular file
  • d Directory
  • l Symbolic link

Characters 2-4: Owner Permissions

  • r Read allowed
  • w Write allowed
  • x Execute allowed
  • - No permission

Characters 5-7: Group Permissions

  • r Read allowed
  • - Write not allowed
  • - Execute not allowed

Characters 8-10: Others Permissions

  • r Read allowed
  • - Write not allowed
  • - Execute not allowed

Understanding Permissions Through Examples

-rw-r--r--

Regular File

  • Owner: Read and write
  • Group: Read only
  • Others: Read only

Use case: General documents

-rwxr-xr-x

Executable File

  • Owner: Read, write, execute
  • Group: Read and execute
  • Others: Read and execute

Use case: Executable scripts

drwxr-xr-x

Directory

  • Owner: Full access
  • Group: Browse and navigate
  • Others: Browse and navigate

Use case: Public directory

-rw-------

Private File

  • Owner: Read and write
  • Group: No access
  • Others: No access

Use case: Private keys, config files

4. chmod - Changing Permissions

Use chmod (Change Mode) command to modify file or directory permissions.

Symbolic Method

Basic Syntax

chmod [who][operation][permission] file
  • who: u (user), g (group), o (others), a (all)
  • operation: + (add), - (remove), = (set)
  • permission: r (read), w (write), x (execute)

Example: Add execute permission for owner

$ chmod u+x script.sh

Example: Remove write permission from group

$ chmod g-w file.txt

Example: Grant read permission to all users

$ chmod a+r document.pdf

Numeric Method

Commonly Used Permission Settings

$ chmod 755 script.sh    # rwxr-xr-x
$ chmod 644 file.txt     # rw-r--r--
$ chmod 600 private.key  # rw-------
$ chmod 777 public/      # rwxrwxrwx (DANGEROUS!)

Common Permission Patterns

Number Permission Use Case
755 rwxr-xr-x Executables, directories
644 rw-r--r-- Regular files
600 rw------- Private keys, config files
700 rwx------ Private directories

Recursive Changes

Change all files below directory

$ chmod -R 755 /path/to/directory/

🛡️ Safe Permission Changing Tips

1. Always check current permissions

$ ls -l filename

Understand current state before changing

2. Principle of Least Privilege

Grant only minimum necessary permissions

  • Read only needed → 644
  • Execution also needed → 755
  • Private → 600/700

3. Gradual Changes

$ chmod u+x file.sh    # Owner only first
$ chmod g+x file.sh     # Then group if OK

Don't make large changes at once, adjust gradually

🎯 Next Steps

In the basics edition, you learned Linux permission system fundamentals, safe chmod operations, and dangerous patterns beginners fall into.

In the advanced edition, you'll master more sophisticated permission management techniques including chown, chgrp, umask, and special permissions.

🔐 Permission Management Series

  1. Basics Edition (This Article) - Permission mechanisms, risk avoidance, chmod basics
  2. Advanced Edition - chown, group management, umask, special permissions
  3. Practical Edition - Real-world scenarios, troubleshooting, security
📢 Affiliate Link Disclosure

This site participates in the Amazon Associates Program, an affiliate advertising program designed to provide means for sites to earn advertising fees by advertising and linking to Amazon.co.jp. Product prices are not affected.

🎉 Master Permission Management Through Practice

After acquiring knowledge from books, solidify your learning by hands-on practice with Penguin Gym Linux exercises. Use chmod, permissions, and security measures in practice to reliably improve your skills.