4.3c chmod, chown, chgrp: changing permissions and ownership

📦 Operating System Layer 📖 Core Linux Administration for AI Operators

When managing AI infrastructure, you'll frequently need to control who can read, write, or execute files and directories. This is critical for protecting model weights, training data, and configuration files. The three core commands for managing these permissions are chmod (change mode), chown (change owner), and chgrp (change group). This section explains how each works in simple, practical terms.

⚙️ Understanding Linux Permissions Basics

Every file and directory in Linux has three permission categories:

  • Owner — The user who created the file
  • Group — A collection of users who share access
  • Others — Everyone else on the system

Each category has three permission types:

  • Read (r) — View file contents or list directory contents
  • Write (w) — Modify file contents or create/delete files in a directory
  • Execute (x) — Run a file as a program or access a directory

Permissions are displayed as a 10-character string when you run ls -l. For example, -rwxr-xr-- means the owner has read, write, and execute; the group has read and execute; others have only read.


🛠️ chmod — Changing Permissions (Mode)

chmod lets you modify the read, write, and execute permissions for a file or directory. You can use either symbolic mode (letters) or numeric mode (numbers).

Symbolic Mode (Using Letters)

You specify who to change permissions for and what to add or remove:

  • u = owner (user)
  • g = group
  • o = others
  • a = all (owner + group + others)
  • + = add permission
  • - = remove permission
  • = = set exact permission

Examples:

  • To add execute permission for the owner on a script file: chmod u+x model_train.py
  • To remove write permission for the group on a config file: chmod g-w config.yaml
  • To set read and write for owner, read-only for group and others: chmod u=rw,go=r dataset.csv

Numeric Mode (Using Numbers)

Each permission type has a numeric value:

  • r = 4
  • w = 2
  • x = 1

Add these values together for each category (owner, group, others). The result is a three-digit number.

Examples:

  • chmod 755 inference_script.sh — Owner gets 7 (4+2+1 = rwx), group gets 5 (4+0+1 = r-x), others get 5 (r-x)
  • chmod 644 training_data.csv — Owner gets 6 (4+2+0 = rw-), group gets 4 (r--), others gets 4 (r--)
  • chmod 700 private_key.pem — Owner gets full access (rwx), group and others get nothing (---)

📊 Visual Representation: File Attributes Administration Commands

This flowchart summarizes how the three administration commands (chmod, chown, and chgrp) modify different aspects of file security and ownership attributes.

flowchart LR target["Target File:<br>model_weights.pt"] --> chmod["chmod 640<br>(Modify Access Mode / Permissions)"] target --> chown["chown admin<br>(Change User Owner)"] target --> chgrp["chgrp gpu-users<br>(Change Group Owner)"] classDef cpu fill:#eafaf1,stroke:#76b900,stroke-width:2px,rx:6px,ry:6px; classDef memory fill:#f0f7ff,stroke:#3498db,stroke-width:1.5px,rx:4px,ry:4px; classDef system fill:#f1f5f9,stroke:#64748b,stroke-width:1.5px; class target cpu; class chmod memory; class chown,chgrp system;

👤 chown — Changing File Owner

chown changes which user owns a file or directory. This is important when transferring files between team members or setting up shared AI resources.

Examples:

  • To change the owner of a model file to user alice: chown alice model_v2.pt
  • To change both owner and group at once: chown alice:data-scientists experiment_results.csv
  • To recursively change ownership of an entire directory and its contents: chown -R bob /projects/ai-training

👥 chgrp — Changing File Group

chgrp changes the group associated with a file or directory. This is useful when multiple engineers need shared access to AI assets.

Examples:

  • To change the group of a dataset to ml-team: chgrp ml-team training_data_2024.csv
  • To recursively change the group of a project folder: chgrp -R ai-researchers /shared/models

📊 Comparison Table: chmod vs chown vs chgrp

Command What It Changes Typical Use Case
chmod Read, write, execute permissions Making a script executable or protecting sensitive data
chown File or directory owner Transferring ownership to another engineer or service account
chgrp File or directory group Granting access to a team without changing individual permissions

🕵️ Practical Tips for AI Infrastructure

  • Protect model weights — Use chmod 600 or chmod 700 on private model files so only the owner can read or modify them.
  • Share datasets with teams — Set group ownership with chgrp and give the group read permissions with chmod g+r.
  • Make scripts executable — Always use chmod +x on any Python or Bash script you plan to run directly.
  • Check current permissions first — Use ls -l to see the current state before making changes.
  • Use recursive changes carefully — The -R flag applies changes to all files and subdirectories. Double-check before running it on large directories.

✅ Summary

Managing permissions and ownership is a fundamental skill for any engineer working with AI infrastructure. The three commands work together:

  • chmod controls what actions are allowed (read, write, execute)
  • chown assigns who owns the file
  • chgrp assigns which group has access

By mastering these commands, you can ensure that AI resources like training data, model checkpoints, and configuration files remain secure and accessible only to the right people.