Apps Artificial Intelligence CSS DevOps Go JavaScript Laravel Linux MongoDB MySQL PHP Python Rust Svelte Vue

Linux File Permissions: A Practical Guide for Developers

1 min read .
Linux File Permissions: A Practical Guide for Developers

Linux file permissions control who can read, modify, or execute files and who can traverse or modify directories. Understanding them is essential for development, deployment, and server administration.

Permission Classes

Permissions are defined for:

  • user (u) — the file owner;
  • group (g) — users in the file’s group;
  • others (o) — everyone else.

The basic permission bits are:

  • read (r);
  • write (w);
  • execute (x).

For directories, r allows listing names, w allows creating/removing entries when combined with appropriate access, and x allows traversal.

Inspect Permissions

ls -l file.txt

Example:

-rwxr-xr-x 1 user group 4096 Aug 18 10:00 file.txt

The three rwx groups represent owner, group, and others.

Change Permissions with chmod

Symbolic mode:

chmod u+x script.sh
chmod g-w file.txt
chmod o= file.txt

Numeric mode uses 4 for read, 2 for write, and 1 for execute:

chmod 755 script.sh  # rwxr-xr-x
chmod 640 config     # rw-r-----

Avoid using 777 as a routine fix; granting write access to everyone usually creates unnecessary security risk.

Change Ownership

sudo chown alice file.txt
sudo chgrp dev_team file.txt
sudo chown alice:dev_team file.txt

Use recursive ownership changes carefully:

sudo chown -R alice:dev_team /path/to/project

Verify the target path first because a recursive command can affect many files quickly.

Make a Script Executable

chmod u+x script.sh
./script.sh

The script should also have an appropriate shebang, such as:

#!/usr/bin/env bash

Conclusion

Use ls -l to inspect permissions, chmod to change access bits, and chown/chgrp to manage ownership. Grant only the permissions an application or user actually needs, especially on shared or production systems.

Related Posts

chevron-up