chmod Explained: Linux File Permissions, Octal and Symbolic
chmod changes a file's permission bits. A mode is one to four octal digits: each of the last three digits adds read (4), write (2) and execute (1) for the owner, the group and everyone else, so chmod 755 gives rwxr-xr-x and chmod 644 gives rw-r--r--. A symbolic mode such as u+x changes only the bits you name. The umask decides which bits new files start without.
Covered in the guide: Chmod Calculator
The chmod command changes a file’s permission bits, and the quickest way to see the result is the chmod calculator, which converts between octal and symbolic modes as you type. This guide explains what those numbers mean, so that you can read a mode like 644 or 4755 at a glance and pick the narrowest mode that works. It sits in our command-line and system tweaks series.
How do I read rwx permissions?
Every file has three sets of permissions: one for the owner, one for the group and one for everyone else. Each set is a trio of letters, r for read, w for write and x for execute, with a dash where a permission is missing. ls -l prints them as ten characters:
-rwxr-xr-- 1 sam sam 1204 Nov 14 10:02 backup.sh
The first character is the file type: a dash for a file and d for a directory. The next nine are the owner (rwx), the group (r-x) and others (r--). Here the owner may do everything, the group may read and run the file, and everyone else may only read it.
For directories the letters mean something slightly different. Read lets you list the names inside, write lets you create and delete entries, and execute lets you enter the directory and reach what is in it.
What is the difference between octal and symbolic modes?
An octal mode is a number that sets every bit at once, and a symbolic mode describes a change to some bits only. The chmod manual says a mode is either “a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.”
In an octal mode, each digit is the sum of read (4), write (2) and execute (1) for one class:
| Digit | Sum | Letters |
|---|---|---|
| 0 | 0 | --- |
| 1 | 1 | —x |
| 2 | 2 | -w- |
| 3 | 2 + 1 | -wx |
| 4 | 4 | r— |
| 5 | 4 + 1 | r-x |
| 6 | 4 + 2 | rw- |
| 7 | 4 + 2 + 1 | rwx |
The manual says a numeric mode is from one to four octal digits, with omitted digits treated as leading zeros. The second digit is the owner, the third the group and the fourth everyone else. So chmod 754 backup.sh sets rwx for the owner, r-x for the group and r— for others.
A symbolic mode has the form [ugoa][+-=][rwxXst]: who (u owner, g group, o others, a all), an operator (+ add, - remove, = set exactly) and the permissions. Some examples:
chmod u+x backup.shadds execute for the owner and leaves everything else alone.chmod go-w backup.shremoves write from the group and others.chmod u=rwx,go=rx backup.shsets the exact resultrwxr-xr-x, which is 755.chmod a+rX projectadds read for everyone, and adds execute only where it is a directory or already executable.
Use octal when you know the final mode you want. Use symbolic when you want to change one thing without disturbing the rest.
Which chmod modes are the most common?
Most files need one of a handful of modes: 644 for ordinary files, 755 for programs and directories, and 600 or 700 for private data. The table shows what each allows.
| Mode | ls -l | Typical use |
|---|---|---|
| 600 | rw------- | A private file, such as an SSH private key |
| 644 | rw-r—r— | A normal file anyone may read but only you may change |
| 664 | rw-rw-r— | A file a group edits together |
| 700 | rwx------ | A private program or directory |
| 755 | rwxr-xr-x | A program, a script or a directory that others may use |
| 775 | rwxrwxr-x | A directory that a group shares |
These are conventions, not rules from the manual. They follow from the digit values, and they match what the default umask produces: 644 for a new file and 755 for a new directory.
What are setuid, setgid and the sticky bit?
They are three extra bits stored in the first digit of a four-digit mode: setuid is 4, setgid is 2 and the sticky bit is 1. ls -l shows setuid and setgid as an s in place of the owner or group x, and the sticky bit as a t in place of the final x.
The chmod manual describes the sticky bit on a directory, which it calls the restricted deletion flag, as preventing “unprivileged users from removing or renaming a file in the directory unless they own the file or the directory.” It is “commonly found on world-writable directories like /tmp.” That is why mode 1777 on /tmp lets everyone create files but not delete each other’s.
Two details from the manual catch people out. First, chmod clears the setgid bit on a regular file when the file’s group is not one of yours, unless you have appropriate privileges. Second, on directories chmod keeps setuid and setgid unless you say otherwise, so clearing them with a numeric mode needs an extra leading zero (00755), a leading minus (-6000) or a leading equals sign (=755). Setuid programs run with the owner’s privileges, so set the bit only on software you trust and understand.
How do I change permissions recursively?
Add -R, which the manual describes as changing files and directories recursively. The catch is that one octal mode then applies to both, and directories need the execute bit to be usable while most files do not.
A symbolic mode with a capital X handles that in one command:
chmod -R u+rwX,go+rX project/
Capital X adds execute only for directories, and for files that already have execute set for some user. To give files and directories exact, separate modes, use find, which can select by type (-type f or -type d) and run a command on the matches with -exec:
find project/ -type d -exec chmod 755 {} +
find project/ -type f -exec chmod 644 {} +
Run these on a copy or a small tree first, and never run a recursive chmod from the root of a drive. The manual lists a --preserve-root option that makes chmod refuse to operate recursively on /.
What does umask do?
The umask is the set of permission bits that are turned off when a new file or directory is created. The umask(2) manual says permissions in the umask “are turned off from the mode argument” a program passes when it creates something.
The typical default is 022. A program creating a file usually asks for mode 0666, and 0666 & ~022 equals 0644, so you get rw-r--r--. A new directory asks for 0777 and ends up as 755. With a stricter umask of 077, new files are 600 and new directories are 700, which keeps everything private by default.
Bash’s umask builtin prints the current mask when you run it with no argument, and sets it when you give a mode, for example umask 027 for the current shell. If the parent directory has a default ACL, the manual says the umask is ignored and the ACL is inherited instead.
How do I convert a mode with the calculator?
Open the chmod calculator, pick checkboxes, octal or symbolic entry, and read the octal mode, the ls -l string, the ready-to-copy chmod command and the umask that would give the same result. The calculator follows the same Ubuntu manual pages cited here and runs in your browser.
It is the faster route when you are unsure, for example when you want to know what u=rwxs,g=rx,o= becomes.
Worked example: private script that the group may run
You want a deploy script that you can edit, your group can run but not change, and others cannot touch.
- Owner: read, write, execute is 4+2+1 = 7.
- Group: read, execute is 4+1 = 5.
- Others: nothing is 0.
The mode is 750, shown as rwxr-x---. The command is chmod 750 deploy.sh. The symbolic form of the same change is chmod u=rwx,g=rx,o= deploy.sh.
Where to go next
Schedule the script you just made executable with our guide to cron syntax on Ubuntu. For the shell basics around it, see how to paste a command into the terminal and how to enable sudo autocomplete, which makes typing long commands easier.
Permissions are a security control. Choose the narrowest mode that lets the job work, keep write access to yourself where you can, and treat any mode that gives write to others as a last resort.
Questions readers ask
What does chmod 755 mean?
The three digits are the owner, the group and everyone else. 7 is 4+2+1, so the owner can read, write and execute. 5 is 4+1, so the group and everyone else can read and execute but not write. ls -l shows it as rwxr-xr-x. It is a common mode for programs, scripts and directories that other users need to enter.
How do I change permissions recursively?
Add the -R option, as in chmod -R 750 project, which the manual describes as changing files and directories recursively. A single mode applies to everything inside, including plain files, so it often gives files the execute bit they should not have. Use a symbolic mode with a capital X, as in chmod -R u+rwX,go+rX project, or use find to treat files and directories separately.
What is the difference between chmod and chown?
chown changes who owns a file: the user, the group, or both. chmod changes what the owner, the group and everyone else are allowed to do with it. A file with mode 600 owned by you is readable by you alone, but changing the owner with chown hands that access to someone else. Changing ownership usually needs sudo; changing the mode needs ownership of the file.
What is umask?
The umask is a mask that turns permission bits off when a program creates a file or directory. The umask(2) manual gives the typical default of 022 and the example 0666 and not 022 equals 0644. So new files normally start as 644 and new directories as 755. Run umask with no arguments in Bash to print the current value, in octal.
Why is chmod 777 unsafe?
Mode 777 gives read, write and execute to the owner, the group and every other user on the machine. Anyone who can log in, and any service running under another account, can then change or replace the file. Almost every permission problem is fixed by a narrower mode, such as 755 for a program or 644 for a data file, or by correcting the owner or group with chown.
How do I make a script executable?
Run chmod u+x script.sh to add the execute bit for the owner only, or chmod 755 script.sh to set the full mode. You can then run it as ./script.sh. The execute bit is separate from the file's contents: a script without it can still be run by passing it to an interpreter, as in bash script.sh, which only needs read permission.
Further reading
- chmod(1) manual page, Ubuntu 24.04 (Noble) (manpages.ubuntu.com)
- chown(1) manual page, Ubuntu 24.04 (Noble) (manpages.ubuntu.com)
- umask(2) manual page, Ubuntu 24.04 (Noble) (manpages.ubuntu.com)
- bash(1) manual page, Ubuntu 24.04 (Noble): the umask builtin (manpages.ubuntu.com)
- find(1) manual page, Ubuntu 24.04 (Noble) (manpages.ubuntu.com)
Worth reading next
- Translate Text Using Ubuntu Command Line
Translate text from the Ubuntu terminal with translate-shell. Install it, translate words, sentences and files, pick an engine, and fix common errors.
- Cron Syntax: How to Schedule Jobs on Ubuntu
Learn the five cron fields, special strings like @daily, common schedules, the percent-sign trap and how crontab -e works on Ubuntu, with a worked example.
- Paste Text or Commands in Ubuntu Terminal
Paste text or commands in the Ubuntu terminal with Ctrl+Shift+V, the right-click menu or middle click. Fixes for when paste fails, plus safety tips.
- Enable Sudo Command Autocomplete in Ubuntu
Fix sudo tab completion in Ubuntu by installing bash-completion and loading it from ~/.bashrc. Includes checks, troubleshooting and shell notes.
- Convert Ext3 to Ext4 Partitions Without Formatting the Hard Disk
Convert an ext3 partition to ext4 in place with tune2fs and e2fsck, without formatting. Backup steps, commands, limits and when a fresh ext4 is better.
- Dalle: Tool to Merge Split Files in Ubuntu
Join split files in Ubuntu with cat or the Dalle tool. Learn split options, file order, checksums, and what to do with pieces from other splitters.