Home/Blog/chmod Explained: Linux File Permissions for Developers
๐Ÿ”
chmod calculatorchmod 755chmod 777

chmod Explained: Linux File Permissions for Developers

Master Linux file permissions with chmod. Understand octal notation, symbolic mode, chmod 755 vs 777 vs 644, and real-world examples for web servers and scripts.

May 1, 20265 min readby ToolNinja

What Is chmod?

chmod (change mode) is the Linux command for setting file and directory permissions. Every file on a Unix-like system has three permission sets โ€” owner, group, and others โ€” and three permission types: read (r), write (w), and execute (x).

Getting permissions right is fundamental to security. Too permissive (chmod 777) and you expose yourself to attacks; too restrictive and your application breaks at 3 AM.


Understanding the Octal System

Each permission set maps to a 3-bit binary number:

PermissionBinaryOctal
---0000
--x0011
-w-0102
-wx0113
r--1004
r-x1015
rw-1106
rwx1117

A three-digit octal like 755 means:

  • 7 (rwx) โ€” owner can read, write, execute
  • 5 (r-x) โ€” group can read and execute
  • 5 (r-x) โ€” others can read and execute

The Most Common chmod Values

chmod 755 โ€” Standard executable / directory

chmod 755 /var/www/html
chmod 755 deploy.sh

Use this for directories and scripts that need to be readable and executable by everyone, but writable only by the owner. This is the standard for web server document roots.

chmod 644 โ€” Standard file

chmod 644 index.html
chmod 644 config.ini

The default for regular files: owner can read and write, everyone else can only read. Perfect for web content files, config files, and logs.

chmod 600 โ€” Private files

chmod 600 ~/.ssh/id_rsa
chmod 600 .env

Owner read/write only. Required for SSH private keys โ€” SSH will refuse to use a key file that's too permissive. Also good practice for .env files and credentials.

chmod 777 โ€” Avoid in production

# โš ๏ธ Everyone can read, write, and execute
chmod 777 uploads/

chmod 777 makes a file or directory fully open to every user on the system. Only use this for temporary debugging or in local dev environments where security doesn't matter. Never on a production server.

chmod 700 โ€” Private directory

chmod 700 ~/.ssh

Owner-only access. Standard for the ~/.ssh directory itself.


Symbolic Mode vs Octal Mode

You don't have to memorize octal. Symbolic mode uses letters:

# Add execute permission for owner
chmod u+x script.sh

# Remove write permission from group and others
chmod go-w sensitive.conf

# Set read for all
chmod a+r public.html

# Set exact permissions symbolically
chmod u=rwx,g=rx,o=rx /usr/local/bin/app

Symbolic mode is great for adding or removing a specific bit without affecting the others.


Recursive chmod with -R

To apply permissions to a directory and everything inside it:

chmod -R 755 /var/www/html

Warning: Be careful with -R โ€” applying execute permission recursively to a directory of HTML files doesn't hurt, but it's sloppy. A more precise approach:

# Directories get 755, files get 644
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

Special Permission Bits

Beyond the standard rwx, there are three special bits:

Setuid (4xxx)

chmod 4755 /usr/bin/passwd

When set on an executable, it runs as the file owner rather than the user who launched it. Used by passwd, sudo, and similar system tools.

Setgid (2xxx)

chmod 2775 /shared/project

On a directory, new files inherit the directory's group rather than the creator's primary group. Useful for shared project folders.

Sticky bit (1xxx)

chmod 1777 /tmp

On a directory, only the file owner (and root) can delete their own files โ€” even if others have write permission. This is how /tmp works.


Reading Permissions with ls -l

ls -la ~/.ssh
# -rw------- 1 user user 3.4K May  1 09:00 id_rsa
# -rw-r--r-- 1 user user  742 May  1 09:00 id_rsa.pub
# drwx------ 2 user user 4.0K May  1 09:00 .

The first character indicates type (- = file, d = directory, l = symlink), then three groups of three permission characters.


Common Real-World Setups

ContextPathchmod
Web root directory/var/www/html755
Web content files/var/www/html/*.html644
PHP/script files/var/www/html/*.php644
SSH private key~/.ssh/id_rsa600
SSH directory~/.ssh700
Environment file.env600
Shell scriptdeploy.sh755
Upload directoryuploads/775
Shared config/etc/app.conf644

Quick Reference: Octal to Symbolic

OctalSymbolicMeaning
777rwxrwxrwxFull access for everyone (avoid)
755rwxr-xr-xOwner full, others read/exec
750rwxr-x---Owner full, group read/exec, no others
644rw-r--r--Owner read/write, others read
640rw-r-----Owner read/write, group read
600rw-------Owner read/write only
700rwx------Owner full, no others
444r--r--r--Read-only for everyone

Try It: ToolNinja Chmod Calculator

Calculating octal values by hand is error-prone. Use the ToolNinja Chmod Calculator to click checkboxes and instantly see the octal value, symbolic notation, and a ready-to-run chmod command.

No login, no tracking โ€” runs 100% in your browser.

Share:๐• Twitterin LinkedIn

Frequently Asked Questions

What does chmod 755 mean?

chmod 755 gives the owner full read, write, and execute permissions (7), while group and others get read and execute only (5). It's the standard permission for web server directories and executable scripts.

What is the difference between chmod 644 and chmod 755?

chmod 644 is for regular files โ€” owner can read and write, everyone else can only read. chmod 755 is for directories and executables โ€” adds execute permission so the directory can be entered or the file can be run.

Is chmod 777 dangerous?

Yes, especially on production servers. chmod 777 gives every user on the system full read, write, and execute access. This can allow malicious users or compromised processes to modify or delete your files. Always use the most restrictive permissions that still allow your application to function.

How do I apply chmod recursively to a directory?

Use chmod -R 755 /your/directory to apply permissions recursively. For better control, use find to apply different permissions to files vs directories separately.

๐Ÿฅท ToolNinja