Linux chmod chown Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki

Linux chmod and chown Guide

Complete beginner-friendly guide to chmod and chown on Linux, covering Arch Linux, CachyOS, and other distributions including file permissions, ownership, and access control.


Table of Contents

  1. Understanding Permissions
  2. chmod Usage
  3. chown Usage
  4. Permission Examples
  5. Troubleshooting

Understanding Permissions

File Permissions

Three permission types:

  • Read (r): View file contents
  • Write (w): Modify file
  • Execute (x): Run file as program

Three permission groups:

  • Owner: File owner
  • Group: File group
  • Others: Everyone else

Permission Numbers

Numeric values:

  • 4: Read
  • 2: Write
  • 1: Execute
  • 7: Read + Write + Execute (4+2+1)
  • 6: Read + Write (4+2)
  • 5: Read + Execute (4+1)

chmod Usage

Change Permissions

Basic syntax:

# Change permissions
chmod permissions file

# Numeric mode
chmod 755 file.txt

# Symbolic mode
chmod u+x file.txt

Numeric Mode

Set permissions:

# Owner: read+write+execute, Group: read+execute, Others: read+execute
chmod 755 file.txt

# Owner: read+write, Group: read, Others: read
chmod 644 file.txt

# Owner: read+write+execute, Group: none, Others: none
chmod 700 file.txt

Symbolic Mode

Modify permissions:

# Add execute for owner
chmod u+x file.txt

# Remove write for group
chmod g-w file.txt

# Add read for others
chmod o+r file.txt

# Set all permissions
chmod a=rwx file.txt

chown Usage

Change Ownership

Basic syntax:

# Change owner
chown user file.txt

# Change owner and group
chown user:group file.txt

# Recursive
chown -R user:group directory/

Examples

Common uses:

# Change owner
sudo chown username file.txt

# Change owner and group
sudo chown username:groupname file.txt

# Change recursively
sudo chown -R username:groupname directory/

Permission Examples

Common Permissions

File permissions:

# Executable script
chmod 755 script.sh

# Configuration file
chmod 644 config.conf

# Private file
chmod 600 private.txt

# Directory
chmod 755 directory/

Directory Permissions

Directory needs:

  • Read: List directory contents
  • Write: Create/delete files
  • Execute: Enter directory
# Standard directory
chmod 755 directory/

# Private directory
chmod 700 directory/

Troubleshooting

Permission Denied

Fix permissions:

# Check current permissions
ls -l file.txt

# Add execute permission
chmod +x file.txt

# Or use sudo
sudo chmod 755 file.txt

Ownership Issues

Fix ownership:

# Check ownership
ls -l file.txt

# Change owner
sudo chown username file.txt

Summary

This guide covered chmod and chown usage, file permissions, and ownership for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.