chmod 777 gives everyone on the system full control of a file: read, write and execute. chmod 755 lets the owner change a file while everyone else can only read and run it, and chmod 644 lets the owner change it while everyone else can only read it. Each of those three digits is a small sum, and once you can do that sum in your head, every permission number makes sense. This guide covers the math, the difference between files and directories, why 777 is the wrong fix for a "Permission denied" error, and how umask decides the permissions new files start with.

The three digits: owner, group, others

Every file on Linux and other Unix-like systems has an owner and a group. A mode like 755 has one digit for each of three classes of user, always in this order:

  1. Owner (also called the user, u): the account that owns the file.
  2. Group (g): members of the file's group.
  3. Others (o): every other account on the system.

Each digit is built from three permission bits: read is worth 4, write is worth 2, and execute is worth 1. Add the ones you want. Read plus write is 4 + 2 = 6; read plus execute is 4 + 1 = 5; all three is 7. The numbers are octal, base 8, which is why no digit goes above 7. The GNU coreutils manual lists the same values: 400, 200 and 100 for the owner, 40, 20 and 10 for the group, and 4, 2 and 1 for others.

DigitLettersSumMeaning
7rwx4 + 2 + 1read, write, execute
6rw-4 + 2read, write
5r-x4 + 1read, execute
4r--4read only
3-wx2 + 1write, execute
2-w-2write only
1--x1execute only
0---0no access

Each digit is really a 3-bit binary number: 5 is 101, which maps to r-x. If that looks familiar, converting binary to decimal uses exactly the same place values.

Common chmod values and when to use them

The letters are what ls -l shows after the first character (which is - for a file and d for a directory). So a file at 644 lists as -rw-r--r--.

Models -l showsTypical use
777rwxrwxrwxAlmost never. Anyone on the system can change or replace it.
775rwxrwxr-xShared project directories where a group edits together
755rwxr-xr-xDirectories, scripts and programs: owner edits, everyone else can read and run
750rwxr-x---Directories or programs only the owner and group should reach
700rwx------Private directories, such as ~/.ssh
664rw-rw-r--Files a group edits together
644rw-r--r--Ordinary files: web pages, images, config files, documents
640rw-r-----Config files the group may read but others must not
600rw-------Secrets: private keys, credential and token files

Files vs directories: what read, write and execute really mean

The same three bits mean different things on a directory. Per the GNU manual's description of mode bits:

Two practical results follow. First, a directory almost always needs execute permission for anyone who should use it, which is why directories are 755 and files are 644. A directory set to 644 can't be entered even by people who can read it. Second, deleting a file is controlled by the directory's permissions, not the file's. If someone can write to a directory, they can delete or replace any file in it, even one they can't read, unless the directory has the sticky bit (covered below).

Work out any mode without the math

Tick the boxes for owner, group and others to get the octal number, the rwx string and the chmod command.

chmod Calculator →

Why chmod 777 is risky

777 is the most-searched chmod value because it makes permission errors go away. It does that by removing every restriction:

A "Permission denied" error usually means the wrong account owns the file, not that the permissions are too tight. Fix the ownership instead:

# Give the files to the account that needs to write them
sudo chown -R deploy:www-data /var/www/site

# Or let a group share write access without opening it to everyone
chmod 775 /var/www/site/uploads
chmod 664 /var/www/site/uploads/*

The account and group names above are examples; use the ones your system actually runs under.

Symbolic mode: the other way to write chmod

Instead of numbers, you can name the class (u, g, o, or a for all), an operator (+ to add, - to remove, = to set exactly), and the permissions:

chmod u+x deploy.sh      # add execute for the owner only
chmod go-w config.yml    # remove write from group and others
chmod u=rw,go=r notes.txt   # same result as chmod 644

Symbolic mode is safer for small changes because it only touches the bits you name. A number always sets all of them at once.

Setting permissions on a whole tree

chmod -R 755 on a folder also marks every file inside as executable, which is rarely what you want. Two better options:

# Capital X adds execute only to directories
# (and to files that are already executable for someone)
chmod -R u=rwX,go=rX /var/www/site

# Or treat directories and files separately
find /var/www/site -type d -exec chmod 755 {{}} +
find /var/www/site -type f -exec chmod 644 {{}} +

umask: why new files start as 644

You rarely run chmod on brand-new files because the umask already set their permissions. POSIX describes the umask as the file mode creation mask: any bit set in the mask is removed from a new file's permissions. Programs typically ask for 666 on new files and 777 on new directories, and the mask takes bits away. On a GNU/Linux system, touch and mkdir give these results:

umaskNew fileNew directory
022644 (rw-r--r--)755 (rwxr-xr-x)
002664 (rw-rw-r--)775 (rwxrwxr-x)
077600 (rw-------)700 (rwx------)

Run umask to see the current value, or umask -S for a symbolic form such as u=rwx,g=rx,o=rx. Note that the mask removes bits; it doesn't subtract. With a umask of 033, a new file gets 644, not 666 − 033 = 633, because the execute bits it clears were never requested.

Special bits: the fourth digit

A mode can have four digits. The extra leading digit holds three special bits: 4 for set-user-ID, 2 for set-group-ID, and 1 for the sticky bit (the GNU manual calls it the restricted deletion flag).

A capital S or T in the listing means the special bit is set but the execute bit under it isn't. On a regular file, rwSr--r-- (4644) is almost always a mistake.

One GNU quirk: on a directory, chmod 755 keeps an existing set-group-ID bit, while chmod =755 clears it. Check the result with stat -c '%a %A' name, which prints both the number and the letters.

Quick reference

For more command-line and browser helpers, see browser-based tools that save developers time.

Frequently asked questions

What does chmod 777 mean?

chmod 777 gives read, write and execute permission to the owner, the group and every other user on the system. It shows as rwxrwxrwx. Anyone with an account can change, replace or run the file.

What is the difference between chmod 755 and 644?

755 (rwxr-xr-x) lets the owner read, write and execute, and everyone else read and execute. 644 (rw-r--r--) lets the owner read and write, and everyone else only read. Use 755 for directories and programs, and 644 for ordinary files.

Why does a directory need execute permission?

On a directory, execute means search: permission to enter it and reach the files inside. Read alone lets you list the names but not open the files, so directories that people should browse normally need both read and execute, as in 755.

What permissions should an SSH private key have?

Use 600, so only the owner can read and write it. The OpenSSH manual says private key files should not be accessible by others, and ssh ignores a private key file that is.

Is chmod 777 ever safe?

Rarely. On a single-user machine it may cause no harm, but it is never the right fix for a permission error. Change the owner or group with chown, or give the group write access with 775 or 664, instead.

Related tools